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