{"id":13448788,"url":"https://github.com/dcramer/django-devserver","last_synced_at":"2025-05-14T23:03:30.013Z","repository":{"id":805644,"uuid":"510113","full_name":"dcramer/django-devserver","owner":"dcramer","description":"A drop-in replacement for Django's runserver.","archived":false,"fork":false,"pushed_at":"2020-02-26T17:37:11.000Z","size":287,"stargazers_count":1267,"open_issues_count":59,"forks_count":158,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-05-07T10:56:50.804Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dcramer.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-02-09T20:35:52.000Z","updated_at":"2025-04-10T20:54:28.000Z","dependencies_parsed_at":"2022-07-22T05:01:52.377Z","dependency_job_id":null,"html_url":"https://github.com/dcramer/django-devserver","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-devserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-devserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-devserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcramer%2Fdjango-devserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcramer","download_url":"https://codeload.github.com/dcramer/django-devserver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243355,"owners_count":22038045,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T06:00:21.114Z","updated_at":"2025-05-14T23:03:29.929Z","avatar_url":"https://github.com/dcramer.png","language":"Python","readme":"-----\nAbout\n-----\n\nA drop in replacement for Django's built-in runserver command. Features include:\n\n* An extendable interface for handling things such as real-time logging.\n* Integration with the werkzeug interactive debugger.\n* Threaded (default) and multi-process development servers.\n* Ability to specify a WSGI application as your target environment.\n\n.. note:: django-devserver works on Django 1.3 and newer\n\n------------\nInstallation\n------------\n\nTo install the latest stable version::\n\n\tpip install git+git://github.com/dcramer/django-devserver#egg=django-devserver\n\n\ndjango-devserver has some optional dependancies, which we highly recommend installing.\n\n* ``pip install sqlparse`` -- pretty SQL formatting\n* ``pip install werkzeug`` -- interactive debugger\n* ``pip install guppy`` -- tracks memory usage (required for MemoryUseModule)\n* ``pip install line_profiler`` -- does line-by-line profiling (required for LineProfilerModule)\n\nYou will need to include ``devserver`` in your ``INSTALLED_APPS``::\n\n\tINSTALLED_APPS = (\n\t    ...\n\t    'devserver',            \n\t)\n\nIf you're using ``django.contrib.staticfiles`` or any other apps with management\ncommand ``runserver``, make sure to put ``devserver`` *above* any of them (or *below*,\nfor ``Django\u003c1.7``). Otherwise ``devserver`` will log an error, but it will fail to work\nproperly.\n\n-----\nUsage\n-----\n\nOnce installed, using the new runserver replacement is easy. You must specify verbosity of 0 to disable real-time log output::\n\n\tpython manage.py runserver\n\nNote: This will force ``settings.DEBUG`` to ``True``.\n\nBy 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. \n\nAdditional CLI Options\n~~~~~~~~~~~~~~~~~~~~~~\n\n--werkzeug\n  Tells Django to use the Werkzeug interactive debugger, instead of it's own.\n\n--forked\n  Use a forking (multi-process) web server instead of threaded.\n\n--dozer\n  Enable the dozer memory debugging middleware (at /_dozer)\n\n--wsgi-app\n  Load the specified WSGI app as the server endpoint.\n\nPlease see ``python manage.py runserver --help`` for more information additional options.\n\nNote: You may also use devserver's middleware outside of the management command::\n\n\tMIDDLEWARE_CLASSES = (\n\t    'devserver.middleware.DevServerMiddleware',\n\t)\n\n-------------\nConfiguration\n-------------\n\nThe following options may be configured via your ``settings.py``:\n\nDEVSERVER_ARGS = []\n  Additional command line arguments to pass to the ``runserver`` command (as defaults).\n\nDEVSERVER_DEFAULT_ADDR = '127.0.0.1'\n  The default address to bind to.\n\nDEVSERVER_DEFAULT_PORT = '8000'\n  The default port to bind to.\n\nDEVSERVER_WSGI_MIDDLEWARE\n  A list of additional WSGI middleware to apply to the ``runserver`` command.\n\nDEVSERVER_MODULES = []\n  A list of devserver modules to load.\n\nDEVSERVER_IGNORED_PREFIXES = ['/media', '/uploads']\n  A list of prefixes to surpress and skip process on. By default, ``ADMIN_MEDIA_PREFIX``, ``MEDIA_URL`` and ``STATIC_URL`` (for Django \u003e= 1.3) will be ignored (assuming ``MEDIA_URL`` and ``STATIC_URL`` is relative)\n\n\n-------\nModules\n-------\n\ndjango-devserver includes several modules by default, but is also extendable by 3rd party modules. This is done via the ``DEVSERVER_MODULES`` setting::\n\n\tDEVSERVER_MODULES = (\n\t    'devserver.modules.sql.SQLRealTimeModule',\n\t    'devserver.modules.sql.SQLSummaryModule',\n\t    'devserver.modules.profile.ProfileSummaryModule',\n\t\n\t    # Modules not enabled by default\n\t    'devserver.modules.ajax.AjaxDumpModule',\n\t    'devserver.modules.profile.MemoryUseModule',\n\t    'devserver.modules.cache.CacheSummaryModule',\n\t    'devserver.modules.profile.LineProfilerModule',\n\t)\n\ndevserver.modules.sql.SQLRealTimeModule\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nOutputs queries as they happen to the terminal, including time taken.\n  \nDisable SQL query truncation (used in SQLRealTimeModule) with the ``DEVSERVER_TRUNCATE_SQL`` setting::\n  \n\tDEVSERVER_TRUNCATE_SQL = False\n\nFilter SQL queries with the ``DEVSERVER_FILTER_SQL`` setting::\n  \n\tDEVSERVER_FILTER_SQL = (\n\t\tre.compile('djkombu_\\w+'),  # Filter all queries related to Celery\n\t)\n\ndevserver.modules.sql.SQLSummaryModule\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nOutputs a summary of your SQL usage.\n\ndevserver.modules.profile.ProfileSummaryModule\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nOutputs a summary of the request performance.\n\ndevserver.modules.profile.MemoryUseModule\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nOutputs a notice when memory use is increased (at the end of a request cycle).\n\ndevserver.modules.profile.LineProfilerModule\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nProfiles 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.\n\nAn example of a decorated function::\n  \n\t@devserver_profile(follow=[foo, bar])\n\tdef home(request):\n\t    result['foo'] = foo()\n\t    result['bar'] = bar()\n\nWhen using the decorator, we recommend that rather than import the decoration directly from devserver that you have code somewhere in your project like::\n\n\ttry:\n\t    if 'devserver' not in settings.INSTALLED_APPS:\n\t        raise ImportError\n\t    from devserver.modules.profile import devserver_profile\n\texcept ImportError:\n\t    from functools import wraps\n\t    class devserver_profile(object):\n\t        def __init__(self, *args, **kwargs):\n\t            pass\n\t        def __call__(self, func):\n\t            def nothing(*args, **kwargs):\n\t                return func(*args, **kwargs)\n\t            return wraps(func)(nothing)\n\nBy importing the decoration using this method, devserver_profile will be a pass through decoration if you aren't using devserver (eg in production)\n\n\ndevserver.modules.cache.CacheSummaryModule\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nOutputs a summary of your cache calls at the end of the request.\n\ndevserver.modules.ajax.AjaxDumpModule\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nOutputs the content of any AJAX responses\n  \nChange the maximum response length to dump with the ``DEVSERVER_AJAX_CONTENT_LENGTH`` setting::\n\n\tDEVSERVER_AJAX_CONTENT_LENGTH = 300\n\ndevserver.modules.request.SessionInfoModule\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nOutputs information about the current session and user.\n\n----------------\nBuilding Modules\n----------------\n\nBuilding modules in devserver is quite simple. In fact, it resembles the middleware API almost identically.\n\nLet's take a sample module, which simple tells us when a request has started, and when it has finished::\n\n\tfrom devserver.modules import DevServerModule\n\t\n\tclass UselessModule(DevServerModule):\n\t    logger_name = 'useless'\n\t    \n\t    def process_request(self, request):\n\t        self.logger.info('Request started')\n\t    \n\t    def process_response(self, request, response):\n\t        self.logger.info('Request ended')\n\nThere are additional arguments which may be sent to logger methods, such as ``duration``::\n\n\t# duration is in milliseconds\n\tself.logger.info('message', duration=13.134)\n","funding_links":[],"categories":["Debugging","Debugging Tools","资源列表","Python","调试工具","Debugging Tools [🔝](#readme)","Awesome Python"],"sub_categories":["调试工具","Debugging Tools"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcramer%2Fdjango-devserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcramer%2Fdjango-devserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcramer%2Fdjango-devserver/lists"}