• Stars
    star
    1,269
  • Rank 37,079 (Top 0.8 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created almost 15 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A drop-in replacement for Django's runserver.

About

A drop in replacement for Django's built-in runserver command. Features include:

  • An extendable interface for handling things such as real-time logging.
  • Integration with the werkzeug interactive debugger.
  • Threaded (default) and multi-process development servers.
  • Ability to specify a WSGI application as your target environment.

Note

django-devserver works on Django 1.3 and newer

Installation

To install the latest stable version:

pip install git+git://github.com/dcramer/django-devserver#egg=django-devserver

django-devserver has some optional dependancies, which we highly recommend installing.

  • pip install sqlparse -- pretty SQL formatting
  • pip install werkzeug -- interactive debugger
  • pip install guppy -- tracks memory usage (required for MemoryUseModule)
  • pip install line_profiler -- does line-by-line profiling (required for LineProfilerModule)

You will need to include devserver in your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'devserver',            
)

If you're using django.contrib.staticfiles or any other apps with management command runserver, make sure to put devserver above any of them (or below, for Django<1.7). Otherwise devserver will log an error, but it will fail to work properly.

Usage

Once installed, using the new runserver replacement is easy. You must specify verbosity of 0 to disable real-time log output:

python manage.py runserver

Note: This will force settings.DEBUG to True.

By default, devserver would bind itself to 127.0.0.1:8000. To change this default, DEVSERVER_DEFAULT_ADDR and DEVSERVER_DEFAULT_PORT settings are available.

Additional CLI Options

--werkzeug

Tells Django to use the Werkzeug interactive debugger, instead of it's own.

--forked

Use a forking (multi-process) web server instead of threaded.

--dozer

Enable the dozer memory debugging middleware (at /_dozer)

--wsgi-app

Load the specified WSGI app as the server endpoint.

Please see python manage.py runserver --help for more information additional options.

Note: You may also use devserver's middleware outside of the management command:

MIDDLEWARE_CLASSES = (
    'devserver.middleware.DevServerMiddleware',
)

Configuration

The following options may be configured via your settings.py:

DEVSERVER_ARGS = []

Additional command line arguments to pass to the runserver command (as defaults).

DEVSERVER_DEFAULT_ADDR = '127.0.0.1'

The default address to bind to.

DEVSERVER_DEFAULT_PORT = '8000'

The default port to bind to.

DEVSERVER_WSGI_MIDDLEWARE

A list of additional WSGI middleware to apply to the runserver command.

DEVSERVER_MODULES = []

A list of devserver modules to load.

DEVSERVER_IGNORED_PREFIXES = ['/media', '/uploads']

A list of prefixes to surpress and skip process on. By default, ADMIN_MEDIA_PREFIX, MEDIA_URL and STATIC_URL (for Django >= 1.3) will be ignored (assuming MEDIA_URL and STATIC_URL is relative)

Modules

django-devserver includes several modules by default, but is also extendable by 3rd party modules. This is done via the DEVSERVER_MODULES setting:

DEVSERVER_MODULES = (
    'devserver.modules.sql.SQLRealTimeModule',
    'devserver.modules.sql.SQLSummaryModule',
    'devserver.modules.profile.ProfileSummaryModule',

    # Modules not enabled by default
    'devserver.modules.ajax.AjaxDumpModule',
    'devserver.modules.profile.MemoryUseModule',
    'devserver.modules.cache.CacheSummaryModule',
    'devserver.modules.profile.LineProfilerModule',
)

devserver.modules.sql.SQLRealTimeModule

Outputs queries as they happen to the terminal, including time taken.

Disable SQL query truncation (used in SQLRealTimeModule) with the DEVSERVER_TRUNCATE_SQL setting:

DEVSERVER_TRUNCATE_SQL = False

Filter SQL queries with the DEVSERVER_FILTER_SQL setting:

DEVSERVER_FILTER_SQL = (
    re.compile('djkombu_\w+'),  # Filter all queries related to Celery
)

devserver.modules.sql.SQLSummaryModule

Outputs a summary of your SQL usage.

devserver.modules.profile.ProfileSummaryModule

Outputs a summary of the request performance.

devserver.modules.profile.MemoryUseModule

Outputs a notice when memory use is increased (at the end of a request cycle).

devserver.modules.profile.LineProfilerModule

Profiles view methods on a line by line basis. There are 2 ways to profile your view functions, by setting setting.DEVSERVER_AUTO_PROFILE = True or by decorating the view functions you want profiled with devserver.modules.profile.devserver_profile. The decoration takes an optional argument follow which is a sequence of functions that are called by your view function that you would also like profiled.

An example of a decorated function:

@devserver_profile(follow=[foo, bar])
def home(request):
    result['foo'] = foo()
    result['bar'] = bar()

When using the decorator, we recommend that rather than import the decoration directly from devserver that you have code somewhere in your project like:

try:
    if 'devserver' not in settings.INSTALLED_APPS:
        raise ImportError
    from devserver.modules.profile import devserver_profile
except ImportError:
    from functools import wraps
    class devserver_profile(object):
        def __init__(self, *args, **kwargs):
            pass
        def __call__(self, func):
            def nothing(*args, **kwargs):
                return func(*args, **kwargs)
            return wraps(func)(nothing)

By importing the decoration using this method, devserver_profile will be a pass through decoration if you aren't using devserver (eg in production)

devserver.modules.cache.CacheSummaryModule

Outputs a summary of your cache calls at the end of the request.

devserver.modules.ajax.AjaxDumpModule

Outputs the content of any AJAX responses

Change the maximum response length to dump with the DEVSERVER_AJAX_CONTENT_LENGTH setting:

DEVSERVER_AJAX_CONTENT_LENGTH = 300

devserver.modules.request.SessionInfoModule

Outputs information about the current session and user.

Building Modules

Building modules in devserver is quite simple. In fact, it resembles the middleware API almost identically.

Let's take a sample module, which simple tells us when a request has started, and when it has finished:

from devserver.modules import DevServerModule

class UselessModule(DevServerModule):
    logger_name = 'useless'

    def process_request(self, request):
        self.logger.info('Request started')

    def process_response(self, request, response):
        self.logger.info('Request ended')

There are additional arguments which may be sent to logger methods, such as duration:

# duration is in milliseconds
self.logger.info('message', duration=13.134)

More Repositories

1

mangodb

A database that operates at CLOUD SCALE
Python
883
star
2

taskmaster

A simple distributed queue designed for handling one-off tasks with large sets of tasks
Python
443
star
3

django-ratings

Pluggable rating fields in Django.
Python
409
star
4

django-sphinx

A transparent layer for full-text search using Sphinx and Django
Python
357
star
5

django-uuidfield

A UUIDField for Django
Python
264
star
6

mock-django

Python
224
star
7

logan

Logan is a toolkit for building standalone Django applications
Python
206
star
8

django-db-log

This project is no longer updated. Please see https://sentry.io/ for its successor
Python
122
star
9

wp-lifestream

Lifestreaming plugin for Wordpress
PHP
121
star
10

django-paging

Sexy pagination in Django
Python
108
star
11

django-orm-cache

A caching layer for Django
87
star
12

decruft

python-readability, but faster (mirror-ish)
Python
83
star
13

django-view-as

A Django middleware which allows you to view the site on behalf of a user.
Python
81
star
14

django-idmapper

An identify mapper for the Django ORM
Python
72
star
15

piplint

Piplint validates your current environment against requirements files
Python
62
star
16

python-tools-tmbundle

Adds support for automated PyFlakes linting in TextMate
Python
61
star
17

peated

HTML
61
star
18

django-static-compiler

Python
56
star
19

pdbinject

A Python utility which uses GDB to inject a telnet-able PDB session into an existing process
Python
55
star
20

py-wikimarkup

A MediaWiki-to-HTML parser for Python.
Python
53
star
21

feedreader

An RSS/Atom feed parsing layer for lxml.objectify in Python
Python
52
star
22

django-sentry

This repo has been moved!
49
star
23

django-indexer

A simple key/value store for indexing meta data on JSON-type fields
Python
46
star
24

chardet

Forked version of chardet
Python
41
star
25

sentry-old

(In Development) Sentry 2.x is a realtime event logging and aggregation platform
Python
40
star
26

django-data-tools

Python
38
star
27

django-compositepks

Composite Primary Keys fork
Python
38
star
28

django-oursql

Django database backend for MySQL via oursql.
Python
37
star
29

dotfiles

My personal dotfiles
Shell
36
star
30

quickunit

A Nose plugin which enables determining which tests to run based on the current git diff
Python
34
star
31

hive

My home infrastructure
Jinja
33
star
32

nibbits-shared

Some shared libraries which we have created at Nibbits
Python
28
star
33

numbers

Python Numbers for Humans
Python
26
star
34

sexytime

Python
26
star
35

nexus-memcache

Memcache statistics plugin for Nexus
Python
23
star
36

sentry

THIS REPOSITORY HAS BEEN MOVED
22
star
37

django-notices

A message notification system for Django
Python
22
star
38

django-db-routes

work in progress
Python
20
star
39

peek

Take a peek at whats slowing down your Python application
Python
20
star
40

ghostplusplus

Git Mirror of GHost++
C
20
star
41

kleenex

A Nose plugin designed to detect coverage and only run the tests that matter.
Python
18
star
42

git-owners

Python
16
star
43

nexus-redis

Redis stats in Nexus
Python
16
star
44

pastethat

A Django Pastebin (Pastethat.com)
Python
15
star
45

dateminer

Extract dates from webpages
Python
13
star
46

selenium-saucelabs-python

Selenium driver for Sauce OnDemand
Python
11
star
47

pmp

Python
11
star
48

anti-spam

11
star
49

pytest-django-lite

The bare minimum to integrate py.test with Django.
Python
11
star
50

SublimeFlakes

Inline PyFlakes in Sublime Text 2
Python
11
star
51

objtrack

Generic object 'viewed' status tracking in Django
Python
11
star
52

php-httplib

A port of Python's httplib in PHP
PHP
10
star
53

gitstats

Unofficial fork of GitStats with some bugfixes
Python
10
star
54

panelkit

WIP: A kit for building a tablet-focused Home Assistant UI.
TypeScript
9
star
55

europython-2011

9
star
56

django-bbcode

I'm tired of bitbucket
Python
9
star
57

gitboard

Python
8
star
58

wiki-to-overview

Redmine Plugin: Forward overview to Wiki
Ruby
8
star
59

nose-json

Python
8
star
60

lovelace-nextbus-card

A card giving richer public transit display using NextBus sensors.
TypeScript
7
star
61

pyconsg-tutorial-bootstrap

Python
7
star
62

hass-luxor

FXLuminaire Luxor integration for Home Assistant
Python
6
star
63

tabletop-server

Python
6
star
64

muskrats

TypeScript
6
star
65

nexus-celery

6
star
66

php-database

A simple database library for MySQL and PGSQL.
PHP
6
star
67

djangospot

DjangoSpot.com Source
JavaScript
6
star
68

nose-bisect

Flush out bad tests with easy bisection in Python/Nose
Python
6
star
69

redmine-improved-revisions

Redmine Plugin: Improved revisions in Redmine
Ruby
5
star
70

nibbits-maploader

Nibbits automated map and replay installer
C#
5
star
71

unifi-mqtt

Python
5
star
72

redmine_hudson

Ruby
5
star
73

forward-to-diffs

Redmine plugin: Forward revisions to diffs
Ruby
5
star
74

soundbot

Audio player extension for Phenny
Python
4
star
75

minecraft-tools

Python
4
star
76

site

JavaScript
4
star
77

rss-to-tumblr

Allows importing an rss under a specific set of tags
Python
4
star
78

nexus-postgresql

4
star
79

jinja1-djangosupport

Jinja 1 with updated Django Support
Python
4
star
80

reraise

Python
4
star
81

notsetuptools

Python
4
star
82

protobufs

Google Protocal Buffers
C++
4
star
83

redmine-home-to-projects

Forward a Redmine user to a the project listing when visiting the Home page.
Ruby
4
star
84

djangospot2

DjangoSpot using Pylons and Redis
Python
3
star
85

flask-redis

Redis support for Flask
Python
3
star
86

tabletop-mobile

JavaScript
3
star
87

pyconsg-tutorial-example

Python
3
star
88

raven

THIS PROJECT HAS BEEN MOVED
3
star
89

scmap

Python
3
star
90

gochatter

2
star
91

homeline

very wip
TypeScript
2
star
92

galaxyvalidator

galaxyvalidator.com source
Python
2
star
93

ghostplusplus-nibbits

Nibbit's version of GHost++
C
2
star
94

cask-server

Python
2
star
95

davidcramer-redirect

Redirects links on davidcramer.net to JustCramer.com
Python
2
star
96

redmine_disqus_ci

Disqus CI for Redmine
Ruby
2
star
97

stonescript

1
star
98

ad-alarm-manager

Python
1
star
99

cask-web

TypeScript
1
star
100

gobot

Go
1
star