Ticket #10435: runserver-custom-handler.diff
File runserver-custom-handler.diff, 2.9 KB (added by , 16 years ago) |
---|
-
django/core/management/commands/runserver.py
3 3 import os 4 4 import sys 5 5 6 def load_wsgi_handler(dotted_path): 7 try: 8 dot = dotted_path.rindex('.') 9 except ValueError: 10 raise ValueError, "%r isn't a WSGI handler class" % dotted_path 11 handler_module, handler_classname = dotted_path[:dot], \ 12 dotted_path[dot+1:] 13 __import__(handler_module, {}, {}, []) 14 mod = sys.modules[handler_module] 15 try: 16 return getattr(mod, handler_classname) 17 except AttributeError: 18 raise ValueError, 'Handler module "%s" does not define a "%s" \ 19 class' % (handler_module, handler_classname) 20 6 21 class Command(BaseCommand): 7 22 option_list = BaseCommand.option_list + ( 8 23 make_option('--noreload', action='store_false', dest='use_reloader', default=True, 9 24 help='Tells Django to NOT use the auto-reloader.'), 10 25 make_option('--adminmedia', dest='admin_media_path', default='', 11 26 help='Specifies the directory from which to serve admin media.'), 27 make_option('--handler', dest='wsgihandler', 28 default='django.core.handlers.wsgi.WSGIHandler', 29 help='Specify an alterate WSGI handler class'), 12 30 ) 13 31 help = "Starts a lightweight Web server for development." 14 32 args = '[optional port number, or ipaddr:port]' … … 19 37 def handle(self, addrport='', *args, **options): 20 38 import django 21 39 from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException 22 from django.core.handlers.wsgi import WSGIHandler40 WSGIHandler = load_wsgi_handler(options['wsgihandler']) 23 41 if args: 24 42 raise CommandError('Usage is runserver %s' % self.args) 25 43 if not addrport: -
docs/ref/django-admin.txt
502 502 503 503 django-admin.py runserver --noreload 504 504 505 --handler 506 ~~~~~~~~~ 507 508 Use the ``--handler`` option to specify an alternate WSGI handler class. 509 This allows you to use the development server with a custom handler 510 subclass instead of the default 511 ``django.core.handlers.wsgi.WSGIHandler``. Overriding the WSGI handler 512 is useful in case you want to override any aspect of request handling, 513 such as customizing 500 error handling. This option should be passed a 514 dotted path to a ``WSGIHandler`` subclass. 515 516 Example usage:: 517 518 django-admin.py runserver --handler=wsgi.handler.WSGIHandler 519 505 520 Examples of using different ports and addresses 506 521 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 507 522