diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-07-21 07:57:10 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-07-21 07:57:10 +0000 |
| commit | bfcecbffd37a68b5fffe81954c17aedeacb1ba22 (patch) | |
| tree | f838d3d4ad950943936f2e93b353f2dd9542c6fd /docs | |
| parent | ca7ee4be17b9b3d80559de00c7bcbcafb188d4f1 (diff) | |
Changed/fixed the way Django handles SCRIPT_NAME and PATH_INFO (or
equivalents). Basically, URL resolving will only use the PATH_INFO and the
SCRIPT_NAME will be prepended by reverse() automatically. Allows for more
portable development and installation. Also exposes SCRIPT_NAME in the
HttpRequest instance.
There are a number of cases where things don't work completely transparently,
so mod_python and fastcgi users should read the relevant docs.
Fixed #285, #1516, #3414.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8015 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/fastcgi.txt | 36 | ||||
| -rw-r--r-- | docs/modpython.txt | 20 | ||||
| -rw-r--r-- | docs/settings.txt | 10 |
3 files changed, 63 insertions, 3 deletions
diff --git a/docs/fastcgi.txt b/docs/fastcgi.txt index 78ee9d408c..b0490171b6 100644 --- a/docs/fastcgi.txt +++ b/docs/fastcgi.txt @@ -79,9 +79,9 @@ your ``manage.py`` is), and then run ``manage.py`` with the ``runfcgi`` option:: If you specify ``help`` as the only option after ``runfcgi``, it'll display a list of all the available options. -You'll need to specify either a ``socket``, ``protocol`` or both ``host`` and ``port``. -Then, when you set up your Web server, you'll just need to point it at the host/port -or socket you specified when starting the FastCGI server. +You'll need to specify either a ``socket``, ``protocol`` or both ``host`` and +``port``. Then, when you set up your Web server, you'll just need to point it +at the host/port or socket you specified when starting the FastCGI server. Protocols --------- @@ -209,6 +209,9 @@ This is probably the most common case, if you're using Django's admin site:: .. _mod_rewrite: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html +Django will automatically use the pre-rewrite version of the URL when +constructing URLs with the ``{% url %}`` template tag (and similar methods). + lighttpd setup ============== @@ -336,3 +339,30 @@ detailed above. .. _modpython: ../modpython/#serving-the-admin-files +Forcing the URL prefix to a particular value +============================================ + +Because many of these fastcgi-based solutions require rewriting the URL at +some point inside the webserver, the path information that Django sees may not +resemble the original URL that was passed in. This is a problem if the Django +application is being served from under a particular prefix and you want your +URLs from the ``{% url %}`` tag to look like the prefix, rather than the +rewritten version, which might contain, for example, ``mysite.fcgi``. + +Django makes a good attempt to work out what the real script name prefix +should be. In particular, if the webserver sets the ``SCRIPT_URL`` (specific +to Apache's mod_rewrite), or ``REDIRECT_URL`` (set by a few servers, including +Apache + mod_rewrite in some situations), Django will work out the original +prefix automatically. + +In the cases where Django cannot work out the prefix correctly and where you +wan the original value to be used in URLs, you can set the +``FORCE_SCRIPT_NAME`` setting in your main ``settings`` file. This sets the +script name uniformly for every URL served via that settings file. Thus you'll +need to use different settings files is you want different sets of URLs to +have different script names in this case, but that is a rare situation. + +As an example of how to use it, if your Django configuration is serving all of +the URLs under ``'/'`` and you wanted to use this setting, you would set +``FORCE_SCRIPT_NAME = ''`` in your settings file. + diff --git a/docs/modpython.txt b/docs/modpython.txt index aa1acf5864..44de0e1bd2 100644 --- a/docs/modpython.txt +++ b/docs/modpython.txt @@ -35,6 +35,7 @@ Then edit your ``httpd.conf`` file and add the following:: SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings + PythonOption django.root /mysite PythonDebug On </Location> @@ -45,6 +46,24 @@ This tells Apache: "Use mod_python for any URL at or under '/mysite/', using the Django mod_python handler." It passes the value of ``DJANGO_SETTINGS_MODULE`` so mod_python knows which settings to use. +**New in Django development version:** Because mod_python does not know we are +serving this site from underneath the ``/mysite/`` prefix, this value needs to +be passed through to the mod_python handler in Django, via the ``PythonOption +django.root ...`` line. The value set on that line (the last item) should +match the string given in the ``<Location ...>`` directive. The effect of this +is that Django will automatically strip the ``/mysite`` string from the front +of any URLs before matching them against your ``URLConf`` patterns. If you +later move your site to live under ``/mysite2``, you will not have to change +anything except the ``django.root`` option in the config file. + +When using ``django.root`` you should make sure that what's left, after the +prefix has been removed, begins with a slash. Your URLConf patterns that are +expecting an initial slash will then work correctly. In the above example, +since we want to send things like ``/mysite/admin/`` to ``/admin/``, we need +to remove the string ``/mysite`` from the beginning, so that is the +``django.root`` value. It would be an error to use ``/mysite/`` (with a +trailing slash) in this case. + Note that we're using the ``<Location>`` directive, not the ``<Directory>`` directive. The latter is used for pointing at places on your filesystem, whereas ``<Location>`` points at places in the URL structure of a Web site. @@ -59,6 +78,7 @@ computer, you'll have to tell mod_python where your project can be found: SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings + PythonOption django.root /mysite PythonDebug On **PythonPath "['/path/to/project'] + sys.path"** </Location> diff --git a/docs/settings.txt b/docs/settings.txt index fbe23b5e88..2c9e56abd4 100644 --- a/docs/settings.txt +++ b/docs/settings.txt @@ -578,6 +578,16 @@ these paths should use Unix-style forward slashes, even on Windows. See .. _Testing Django Applications: ../testing/ +FORCE_SCRIPT_NAME +------------------ + +Default: ``None`` + +If not ``None``, this will be used as the value of the ``SCRIPT_NAME`` +environment variable in any HTTP request. This setting can be used to override +the server-provided value of ``SCRIPT_NAME``, which may be a rewritten version +of the preferred value or not supplied at all. + IGNORABLE_404_ENDS ------------------ |
