Ticket #16360: 16360.2.diff
File 16360.2.diff, 17.8 KB (added by , 13 years ago) |
---|
-
django/conf/global_settings.py
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index 7b7531a..73d180c 100644
a b DEFAULT_INDEX_TABLESPACE = '' 412 412 # Default X-Frame-Options header value 413 413 X_FRAME_OPTIONS = 'SAMEORIGIN' 414 414 415 # The import name of the WSGI application. If this is `None` the default 416 # 'django.core.handlers.wsgi.application' is used. Otherwise this shall 417 # point to an actual WSGI application. 418 WSGI_APPLICATION = None 419 415 420 ############## 416 421 # MIDDLEWARE # 417 422 ############## -
django/conf/project_template/settings.py
diff --git a/django/conf/project_template/settings.py b/django/conf/project_template/settings.py index 3a2243f..59a2d22 100644
a b MIDDLEWARE_CLASSES = ( 99 99 100 100 ROOT_URLCONF = '{{ project_name }}.urls' 101 101 102 # The WSGI application used by Django's runserver etc. 103 WSGI_APPLICATION = '{{ project_name }}.wsgi.application' 104 102 105 TEMPLATE_DIRS = ( 103 106 # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". 104 107 # Always use forward slashes, even on Windows. -
new file django/conf/project_template/wsgi.py
diff --git a/django/conf/project_template/wsgi.py b/django/conf/project_template/wsgi.py new file mode 100644 index 0000000..7e37f60
- + 1 """ 2 WSGI config for {{ project_name }} project. 3 4 This module contains the actual WSGI application to be used by Django's 5 development server and the production environment as the global variable 6 named ``application`` and is enabled by setting the ``WSGI_APPLICATION`` 7 setting to '{{ project_name }}.wsgi.application'. 8 9 Of course usually you would have an actual Django WSGI application here, 10 but it also might make sense to replace the whole Django WSGI application 11 with a custom one that later delegates to the Django one (for instance if 12 you want to combine a Django application with an application of another 13 framework). 14 """ 15 from django.core.management import setup_settings 16 17 settings = setup_settings(__name__) 18 19 # The application object is used by the development server 20 # as well as a WSGI server configured to use this file. 21 from django.core.handlers.wsgi import application 22 23 # Apply other WSGI middlewares here. 24 # from helloworld.wsgi import HelloWorldApplication 25 # application = HelloWorldApplication(application) -
django/contrib/staticfiles/handlers.py
diff --git a/django/contrib/staticfiles/handlers.py b/django/contrib/staticfiles/handlers.py index 962b835..d9f6833 100644
a b class StaticFilesHandler(WSGIHandler): 12 12 WSGI middleware that intercepts calls to the static files directory, as 13 13 defined by the STATIC_URL setting, and serves those files. 14 14 """ 15 def __init__(self, application, base_dir=None): 15 def __init__(self, application, base_dir=None, enabled=True): 16 # If not enabled this directly proxies to the given application. 17 self.enabled = enabled 16 18 self.application = application 17 19 if base_dir: 18 20 self.base_dir = base_dir … … class StaticFilesHandler(WSGIHandler): 63 65 return super(StaticFilesHandler, self).get_response(request) 64 66 65 67 def __call__(self, environ, start_response): 66 if notself._should_handle(environ['PATH_INFO']):67 return s elf.application(environ, start_response)68 return s uper(StaticFilesHandler, self).__call__(environ, start_response)68 if self.enabled and self._should_handle(environ['PATH_INFO']): 69 return super(StaticFilesHandler, self).__call__(environ, start_response) 70 return self.application(environ, start_response) -
django/contrib/staticfiles/management/commands/runserver.py
diff --git a/django/contrib/staticfiles/management/commands/runserver.py b/django/contrib/staticfiles/management/commands/runserver.py index c6e56d2..d4e332c 100644
a b class Command(BaseRunserverCommand): 21 21 handler = super(Command, self).get_handler(*args, **options) 22 22 use_static_handler = options.get('use_static_handler', True) 23 23 insecure_serving = options.get('insecure_serving', False) 24 if (settings.DEBUG and use_static_handler or 25 (use_static_handler and insecure_serving)): 26 handler = StaticFilesHandler(handler) 27 return handler 24 enabled = use_static_handler and (settings.DEBUG or insecure_serving) 25 return StaticFilesHandler(handler, enabled=enabled) -
django/core/handlers/base.py
diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index a6c8044..5364e65 100644
a b def get_script_name(environ): 242 242 Returns the equivalent of the HTTP request's SCRIPT_NAME environment 243 243 variable. If Apache mod_rewrite has been used, returns what would have been 244 244 the script name prior to any rewriting (so it's the script name as seen 245 from the client's perspective), unless DJANGO_USE_POST_REWRITE is set (to246 anything).245 from the client's perspective), unless the FORCE_SCRIPT_NAME setting is 246 set (to anything). 247 247 """ 248 248 from django.conf import settings 249 249 if settings.FORCE_SCRIPT_NAME is not None: -
django/core/handlers/wsgi.py
diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py index 56d2ba6..540484d 100644
a b 1 """ 2 WSGI entrypoints 3 4 Overview 5 -------- 6 7 The motivation behind this module is to expose the WSGI application that 8 exists in Django to the actual Django user project. The idea is that you 9 have a documented way to apply WSGI middlewares that are then being used by 10 both the internal WSGI development server as well as any other WSGI server 11 in production. 12 13 The way it works is that there are a handful of WSGI application objects: 14 15 - django.core.handlers.wsgi.WSGIHandler: this is the implementation of the 16 actual Django WSGI dispatcher and it should be considered an 17 implementation detail. While users are free to subclass and extend it, 18 it's not necessarily supported. 19 - django.core.handlers.wsgi.application: this is the documented WSGI 20 application which is used by default. 21 - django.core.handlers.wsgi.django_application: this is the actual WSGI 22 application that is passed to the servers. It's internally proxying to 23 the configured WSGI application and will most likely be a (decorated) 24 version of the `application`. 25 26 The reason why we have multiple applications here is because of the 27 ability to apply middlewares. Basically `application` is the WSGI 28 application without any middlewarse applied, `django_application` is a 29 proxy to the base application + all applied middlewares. 30 31 The middlewares are added according to the WSGI_APPLICATION configuration 32 setting which points to a module that imports the `application` as 33 `application` and can apply middlewares. 34 35 If the WSGI_APPLICATION setting is ``None`` (which is the case for upgraded 36 applications from before we had exposed WSGI support) instead of the regular 37 application, the `application` is used. 38 39 The WSGI_APPLICATION 40 -------------------- 41 42 The WSGI_APPLICATION configuration setting points to an actual WSGI 43 application. By default the project generator will configure that a file 44 called `projectname.wsgi` exists and contains a global variable named 45 `application`. The contents look like this:: 46 47 from django.core.handlers.wsgi import application 48 49 This can be used to apply WSGI middlewares:: 50 51 from helloworld.wsgi import HelloWorldApplication 52 application = HelloWorldApplication(application) 53 54 Of course usually you would have an actual Django WSGI application there, but 55 it also might make sense to replace the whole Django WSGI application with 56 a custom one that later delegates to the Django one (for instance if you 57 want to combine a Django application with an application of another framework). 58 59 """ 60 from __future__ import with_statement 1 61 import sys 2 62 from threading import Lock 3 63 try: … … except ImportError: 7 67 8 68 from django import http 9 69 from django.core import signals 70 from django.core.exceptions import ImproperlyConfigured 10 71 from django.core.handlers import base 11 72 from django.core.urlresolvers import set_script_prefix 12 73 from django.utils import datastructures 13 74 from django.utils.encoding import force_unicode, iri_to_uri 75 from django.utils.importlib import import_module 14 76 from django.utils.log import getLogger 15 77 16 78 logger = getLogger('django.request') … … class WSGIRequest(http.HttpRequest): 190 252 FILES = property(_get_files) 191 253 REQUEST = property(_get_request) 192 254 255 193 256 class WSGIHandler(base.BaseHandler): 194 257 initLock = Lock() 195 258 request_class = WSGIRequest 196 259 197 260 def __call__(self, environ, start_response): 198 from django.conf import settings199 200 261 # Set up middleware if needed. We couldn't do this earlier, because 201 262 # settings weren't available. 202 263 if self._request_middleware is None: … … class WSGIHandler(base.BaseHandler): 242 303 start_response(status, response_headers) 243 304 return response 244 305 306 application = WSGIHandler() 307 308 309 class DjangoWSGIApplication(object): 310 """ 311 Implements a proxy to the actual WSGI application as configured 312 by the user in settings.WSGI_APPLICATION which will usually be the 313 `application`, optionally with middlewares applied. 314 """ 315 def __init__(self): 316 self._instance = None 317 self._instance_lock = Lock() 318 319 def _load_application(self): 320 from django.conf import settings 321 app_path = getattr(settings, 'WSGI_APPLICATION') 322 if app_path is None: 323 return application 324 try: 325 module_name, attr = app_path.rsplit('.', 1) 326 return getattr(import_module(module_name), attr) 327 except (ImportError, AttributeError), e: 328 raise ImproperlyConfigured("WSGI application '%s' could not " 329 "be loaded: %s" % (app_path, e)) 330 331 def __call__(self, environ, start_response): 332 if self._instance is None: 333 with self._instance_lock: 334 self._instance = self._load_application() 335 return self._instance(environ, start_response) 336 337 # the proxy used in deployment 338 django_application = DjangoWSGIApplication() -
django/core/management/__init__.py
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index 1345eaf..d4b51cc 100644
a b def setup_environ(settings_mod, original_settings_path=None): 392 392 # way. For example, if this file (manage.py) lives in a directory 393 393 # "myproject", this code would add "/path/to/myproject" to sys.path. 394 394 if '__init__.py' in settings_mod.__file__: 395 p = os.path.dirname(settings_mod.__file__)395 path = os.path.dirname(settings_mod.__file__) 396 396 else: 397 p = settings_mod.__file__398 project_directory, settings_filename = os.path.split(p )397 path = settings_mod.__file__ 398 project_directory, settings_filename = os.path.split(path) 399 399 if project_directory == os.curdir or not project_directory: 400 400 project_directory = os.getcwd() 401 401 project_name = os.path.basename(project_directory) … … def setup_environ(settings_mod, original_settings_path=None): 425 425 426 426 return project_directory 427 427 428 429 def setup_settings(path): 430 """ 431 Configures the settings first by looking at the environment variable 432 DJANGO_SETTINGS_MODULE or if that fail tries to find it with the 433 given module path. 434 435 Example: 436 437 from django.core.management import setup_settings 438 439 setup_settings(__name__) 440 setup_settings('wsgi') 441 setup_settings('mysite.wsgi') 442 """ 443 try: 444 # Check if DJANGO_SETTINGS_MODULE is already given 445 settings_module = os.environ['DJANGO_SETTINGS_MODULE'] 446 if not settings_module: 447 raise KeyError 448 settings = import_module(settings_module) 449 except KeyError: 450 # Or try importing the settings module two levels up, 451 # so if name is 'mysite.wsgi', it'll try 'mysite.settings' 452 try: 453 settings = import_module('settings', path) 454 except ImportError: 455 # two levels up because name contains the submodule 456 settings = import_module('..settings', path) 457 setup_environ(settings) 458 459 # Return the settings module 460 from django.conf import settings 461 return settings 462 463 428 464 def execute_from_command_line(argv=None): 429 465 """ 430 466 A simple method that runs a ManagementUtility. -
django/core/management/commands/runserver.py
diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py index 2e693e7..c84bf30 100644
a b import sys 5 5 import socket 6 6 7 7 from django.core.management.base import BaseCommand, CommandError 8 from django.core.handlers.wsgi import WSGIHandler8 from django.core.handlers.wsgi import django_application 9 9 from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException 10 10 from django.utils import autoreload 11 11 … … class BaseRunserverCommand(BaseCommand): 37 37 """ 38 38 Returns the default WSGI handler for the runner. 39 39 """ 40 return WSGIHandler()40 return django_application 41 41 42 42 def handle(self, addrport='', *args, **options): 43 43 self.use_ipv6 = options.get('use_ipv6') -
django/core/servers/fastcgi.py
diff --git a/django/core/servers/fastcgi.py b/django/core/servers/fastcgi.py index 9f80d2b..442df44 100644
a b def runfastcgi(argset=[], **kwargs): 139 139 return False 140 140 141 141 # Prep up and go 142 from django.core.handlers.wsgi import WSGIHandler142 from django.core.handlers.wsgi import django_application 143 143 144 144 if options["host"] and options["port"] and not options["socket"]: 145 145 wsgi_opts['bindAddress'] = (options["host"], int(options["port"])) … … def runfastcgi(argset=[], **kwargs): 178 178 fp.write("%d\n" % os.getpid()) 179 179 fp.close() 180 180 181 WSGIServer( WSGIHandler(), **wsgi_opts).run()181 WSGIServer(django_application, **wsgi_opts).run() 182 182 183 183 if __name__ == '__main__': 184 184 runfastcgi(sys.argv[1:]) -
docs/howto/deployment/modwsgi.txt
diff --git a/docs/howto/deployment/modwsgi.txt b/docs/howto/deployment/modwsgi.txt index de3a5b6..90d7ba3 100644
a b the details about how to use mod_wsgi. You'll probably want to start with the 24 24 Basic configuration 25 25 =================== 26 26 27 Once you've got mod_wsgi installed and activated, edit your ``httpd.conf`` file28 and add::27 Once you've got mod_wsgi installed and activated, edit your ``httpd.conf`` 28 file and add:: 29 29 30 WSGIScriptAlias / /path/to/mysite/ apache/django.wsgi30 WSGIScriptAlias / /path/to/mysite/wsgi.py 31 31 32 The first bit above is the url you want to be serving your application at (``/`` 33 indicates the root url), and the second is the location of a "WSGI file" -- see 34 below -- on your system, usually inside of your project. This tells Apache 35 to serve any request below the given URL using the WSGI application defined by that file. 32 The first bit above is the url you want to be serving your application at 33 (``/`` indicates the root url), and the second is the location of a "WSGI 34 file" -- see below -- on your system, usually inside of your project. This 35 tells Apache to serve any request below the given URL using the WSGI 36 application defined by that file. 36 37 37 38 Next we'll need to actually create this WSGI application, so create the file 38 39 mentioned in the second part of ``WSGIScriptAlias`` and add:: 39 40 40 import os41 41 import sys 42 from django.core.management import setup_settings 42 43 43 os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'44 setup_settings(__name__) 44 45 45 import django.core.handlers.wsgi 46 application = django.core.handlers.wsgi.WSGIHandler() 46 # The application object is used by the development server 47 # as well as a WSGI server configured to use this file. 48 from django.core.handlers.wsgi import application 47 49 48 50 If your project is not on your ``PYTHONPATH`` by default you can add:: 49 51 … … If your project is not on your ``PYTHONPATH`` by default you can add:: 51 53 if path not in sys.path: 52 54 sys.path.append(path) 53 55 54 just below the ``import sys`` line to place your project on the path. Remember to55 replace 'mysite.settings' with your correct settings file, and '/path/to/mysite' 56 with your own project's location.56 just below the ``import sys`` line to place your project on the path. 57 Remember to replace 'mysite.settings' with your correct settings file, 58 and ``'/path/to/mysite'`` with your own project's location. 57 59 58 60 .. _serving-files: 59 61 -
docs/howto/deployment/uwsgi.txt
diff --git a/docs/howto/deployment/uwsgi.txt b/docs/howto/deployment/uwsgi.txt index 11cb51c..d3e631e 100644
a b Starting the server 112 112 Example command line for a Web server that understand the uWSGI protocol:: 113 113 114 114 uwsgi --chdir=/path/to/your/project 115 --module=' django.core.handlers.wsgi:WSGIHandler()' \115 --module='wsgi:application' \ 116 116 --env DJANGO_SETTINGS_MODULE=settings \ 117 117 --master --pidfile=/tmp/project-master.pid \ 118 118 --socket=127.0.0.1:49152 \ # can also be a file … … Example command line for a Web server that understand the uWSGI protocol:: 128 128 Django specific options are: 129 129 130 130 * ``chdir``: should be the path to your project 131 * ``module``: uwsgi module to use 131 * ``module``: WSGI module to use, probably the ``wsgi`` module which 132 :djadmin:`startproject` creates. 132 133 * ``pythonpath``: optional path to your project virtualenv 133 134 * ``env``: should contain at least ``DJANGO_SETTINGS_MODULE`` 134 135