Django

Code

Show
Ignore:
Timestamp:
07/21/08 02:57:10 (1 year ago)
Author:
mtredinnick
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/fastcgi.txt

    r7294 r8015  
    8080list of all the available options. 
    8181 
    82 You'll need to specify either a ``socket``, ``protocol`` or both ``host`` and ``port``. 
    83 Then, when you set up your Web server, you'll just need to point it at the host/por
    84 or socket you specified when starting the FastCGI server. 
     82You'll need to specify either a ``socket``, ``protocol`` or both ``host`` and 
     83``port``. Then, when you set up your Web server, you'll just need to point i
     84at the host/port or socket you specified when starting the FastCGI server. 
    8585 
    8686Protocols 
     
    209209 
    210210.. _mod_rewrite: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html 
     211 
     212Django will automatically use the pre-rewrite version of the URL when 
     213constructing URLs with the ``{% url %}`` template tag (and similar methods). 
    211214 
    212215lighttpd setup 
     
    337340.. _modpython: ../modpython/#serving-the-admin-files 
    338341 
     342Forcing the URL prefix to a particular value 
     343============================================ 
     344 
     345Because many of these fastcgi-based solutions require rewriting the URL at 
     346some point inside the webserver, the path information that Django sees may not 
     347resemble the original URL that was passed in. This is a problem if the Django 
     348application is being served from under a particular prefix and you want your 
     349URLs from the ``{% url %}`` tag to look like the prefix, rather than the 
     350rewritten version, which might contain, for example, ``mysite.fcgi``. 
     351 
     352Django makes a good attempt to work out what the real script name prefix 
     353should be. In particular, if the webserver sets the ``SCRIPT_URL`` (specific 
     354to Apache's mod_rewrite), or ``REDIRECT_URL`` (set by a few servers, including 
     355Apache + mod_rewrite in some situations), Django will work out the original 
     356prefix automatically. 
     357 
     358In the cases where Django cannot work out the prefix correctly and where you 
     359wan the original value to be used in URLs, you can set the 
     360``FORCE_SCRIPT_NAME`` setting in your main ``settings`` file. This sets the 
     361script name uniformly for every URL served via that settings file. Thus you'll 
     362need to use different settings files is you want different sets of URLs to 
     363have different script names in this case, but that is a rare situation. 
     364 
     365As an example of how to use it, if your Django configuration is serving all of 
     366the URLs under ``'/'`` and you wanted to use this setting, you would set 
     367``FORCE_SCRIPT_NAME = ''`` in your settings file. 
     368 
  • django/trunk/docs/modpython.txt

    r7294 r8015  
    3636        PythonHandler django.core.handlers.modpython 
    3737        SetEnv DJANGO_SETTINGS_MODULE mysite.settings 
     38        PythonOption django.root /mysite 
    3839        PythonDebug On 
    3940    </Location> 
     
    4546Django mod_python handler." It passes the value of ``DJANGO_SETTINGS_MODULE`` 
    4647so mod_python knows which settings to use. 
     48 
     49**New in Django development version:** Because mod_python does not know we are 
     50serving this site from underneath the ``/mysite/`` prefix, this value needs to 
     51be passed through to the mod_python handler in Django, via the ``PythonOption 
     52django.root ...`` line. The value set on that line (the last item) should 
     53match the string given in the ``<Location ...>`` directive. The effect of this 
     54is that Django will automatically strip the ``/mysite`` string from the front 
     55of any URLs before matching them against your ``URLConf`` patterns. If you 
     56later move your site to live under ``/mysite2``, you will not have to change 
     57anything except the ``django.root`` option in the config file. 
     58 
     59When using ``django.root`` you should make sure that what's left, after the 
     60prefix has been removed, begins with a slash. Your URLConf patterns that are 
     61expecting an initial slash will then work correctly. In the above example, 
     62since we want to send things like ``/mysite/admin/`` to ``/admin/``, we need 
     63to remove the string ``/mysite`` from the beginning, so that is the 
     64``django.root`` value. It would be an error to use ``/mysite/`` (with a 
     65trailing slash) in this case. 
    4766 
    4867Note that we're using the ``<Location>`` directive, not the ``<Directory>`` 
     
    6079        PythonHandler django.core.handlers.modpython 
    6180        SetEnv DJANGO_SETTINGS_MODULE mysite.settings 
     81        PythonOption django.root /mysite 
    6282        PythonDebug On 
    6383        **PythonPath "['/path/to/project'] + sys.path"** 
  • django/trunk/docs/settings.txt

    r7965 r8015  
    578578 
    579579.. _Testing Django Applications: ../testing/ 
     580 
     581FORCE_SCRIPT_NAME 
     582------------------ 
     583 
     584Default: ``None`` 
     585 
     586If not ``None``, this will be used as the value of the ``SCRIPT_NAME`` 
     587environment variable in any HTTP request. This setting can be used to override 
     588the server-provided value of ``SCRIPT_NAME``, which may be a rewritten version 
     589of the preferred value or not supplied at all. 
    580590 
    581591IGNORABLE_404_ENDS