def inner_run(): # Flag the server as active from devserver import settings settings.DEVSERVER_ACTIVE = True settings.DEBUG = True from django.conf import settings from django.utils import translation print "Validating models..." self.validate(display_num_errors=True) print "\nDjango version %s, using settings %r" % ( django.get_version(), settings.SETTINGS_MODULE) print "Development server is running at http://%s:%s/" % (addr, port) print "Quit the server with %s." % quit_command # django.core.management.base forces the locale to en-us. We should # set it up correctly for the first request (particularly important # in the "--noreload" case). translation.activate(settings.LANGUAGE_CODE) try: handler = AdminMediaHandler(DevServerHandler(), admin_media_path) if werkzeug: run_simple(addr, int(port), DebuggedApplication(handler, True), use_reloader=use_reloader, use_debugger=True) else: run(addr, int(port), handler) except WSGIServerException, e: # Use helpful error messages instead of ugly tracebacks. ERRORS = { 13: "You don't have permission to access that port.", 98: "That port is already in use.", 99: "That IP address can't be assigned-to.", } try: error_text = ERRORS[e.args[0].args[0]] except (AttributeError, KeyError): error_text = str(e) sys.stderr.write( self.style.ERROR("Error: %s" % error_text) + '\n') # Need to use an OS exit because sys.exit doesn't work in a thread os._exit(1)
def get_handler(self, *args, **options): if int(options['verbosity']) < 1: handler = WSGIHandler() else: handler = DevServerHandler() # AdminMediaHandler is removed in Django 1.5 # Add it only when it avialable. try: from django.core.servers.basehttp import AdminMediaHandler except ImportError: pass else: handler = AdminMediaHandler(handler, options['admin_media_path']) if 'django.contrib.staticfiles' in settings.INSTALLED_APPS and options[ 'use_static_files']: from django.contrib.staticfiles.handlers import StaticFilesHandler handler = StaticFilesHandler(handler) return handler
def inner_run(): # Flag the server as active from devserver import settings import devserver settings.DEVSERVER_ACTIVE = True settings.DEBUG = True from django.conf import settings from django.utils import translation print "Validating models..." self.validate(display_num_errors=True) print "\nDjango version %s, using settings %r" % ( django.get_version(), settings.SETTINGS_MODULE) print "Running django-devserver %s" % (devserver.get_version(), ) if use_werkzeug: server_type = 'werkzeug' else: server_type = 'django' print "%s %s server is running at http://%s:%s/" % ( options['use_forked'] and 'Forked' or 'Threaded', server_type, addr, port) print "Quit the server with %s." % quit_command # django.core.management.base forces the locale to en-us. We should # set it up correctly for the first request (particularly important # in the "--noreload" case). translation.activate(settings.LANGUAGE_CODE) if int(options['verbosity']) < 1: app = WSGIHandler() else: app = DevServerHandler() if wsgi_app: try: app = __import__(wsgi_app, {}, {}, ['application']).application except (ImportError, AttributeError): raise if options['use_forked']: mixin = SocketServer.ForkingMixIn else: mixin = SocketServer.ThreadingMixIn middleware = getattr(settings, 'DEVSERVER_WSGI_MIDDLEWARE', []) for middleware in middleware: module, class_name = middleware.rsplit('.', 1) app = getattr(__import__(module, {}, {}, [class_name]), class_name)(app) if 'django.contrib.staticfiles' in settings.INSTALLED_APPS and use_static_files: from django.contrib.staticfiles.handlers import StaticFilesHandler app = StaticFilesHandler(app) else: app = AdminMediaHandler(app, admin_media_path) if options['use_dozer']: from dozer import Dozer app = Dozer(app) try: if use_werkzeug: run_simple(addr, int(port), DebuggedApplication(app, True), use_reloader=False, use_debugger=True) else: run(addr, int(port), app, mixin) except WSGIServerException, e: # Use helpful error messages instead of ugly tracebacks. ERRORS = { 13: "You don't have permission to access that port.", 98: "That port is already in use.", 99: "That IP address can't be assigned-to.", } try: error_text = ERRORS[e.args[0].args[0]] except (AttributeError, KeyError): error_text = str(e) sys.stderr.write( self.style.ERROR("Error: %s" % error_text) + '\n') # Need to use an OS exit because sys.exit doesn't work in a thread os._exit(1)