Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Documented how to manually piece together URLs with get_script_name().

Thanks to timo and leovitch for the patch. Fixed #10328.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13772 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 030c97b119bea450cc4e1f289a95e91aa664221c 1 parent 7bb6abe
Malcolm Tredinnick authored September 12, 2010
2  docs/howto/deployment/modpython.txt
... ...
@@ -1,3 +1,5 @@
  1
+.. _howto-deployment-modpython:
  2
+
1 3
 ============================================
2 4
 How to use Django with Apache and mod_python
3 5
 ============================================
21  docs/ref/request-response.txt
@@ -30,10 +30,25 @@ All attributes except ``session`` should be considered read-only.
30 30
 
31 31
 .. attribute:: HttpRequest.path
32 32
 
33  
-   A string representing the full path to the requested page, not including
34  
-   the domain.
  33
+    A string representing the full path to the requested page, not including
  34
+    the domain.
35 35
 
36  
-   Example: ``"/music/bands/the_beatles/"``
  36
+    Example: ``"/music/bands/the_beatles/"``
  37
+
  38
+.. attribute:: HttpRequest.path_info
  39
+
  40
+    Under some web server configurations, the portion of the URL after the host
  41
+    name is split up into a script prefix portion and a path info portion
  42
+    (this happens, for example, when using the ``django.root`` option
  43
+    with the :ref:`modpython handler from Apache <howto-deployment-modpython>`).
  44
+    The ``path_info`` attribute always contains the path info portion of the
  45
+    path, no matter what web server is being used. Using this instead of
  46
+    attr:`~HttpRequest.path` can make your code much easier to move between test
  47
+    and deployment servers.
  48
+
  49
+    For example, if the ``django.root`` for your application is set to 
  50
+    ``"/minfo"``, then ``path`` might be ``"/minfo/music/bands/the_beatles/"``
  51
+    and ``path_info`` would be ``"/music/bands/the_beatles/"``.
37 52
 
38 53
 .. attribute:: HttpRequest.method
39 54
 
19  docs/topics/http/urls.txt
@@ -926,3 +926,22 @@ permalink()
926 926
 The :func:`django.db.models.permalink` decorator is useful for writing short
927 927
 methods that return a full URL path. For example, a model's
928 928
 ``get_absolute_url()`` method. See :func:`django.db.models.permalink` for more.
  929
+
  930
+get_script_prefix()
  931
+-------------------
  932
+
  933
+.. function:: get_script_prefix()
  934
+
  935
+.. versionadded:: 1.0
  936
+
  937
+Normally, you should always use :func:`~django.core.urlresolvers.reverse` or
  938
+:func:`~django.db.models.permalink` to define URLs within your application.
  939
+However, if your application constructs part of the URL hierarchy itself, you
  940
+may occasionally need to generate URLs. In that case, you need to be able to
  941
+find the base URL of the Django project within its web server
  942
+(normally, :func:`~django.core.urlresolvers.reverse` takes care of this for 
  943
+you). In that case, you can call ``get_script_prefix()``, which will return the
  944
+script prefix portion of the URL for your Django project. If your Django
  945
+project is at the root of its webserver, this is always ``"/"``, but it can be
  946
+changed, for instance  by using ``django.root`` (see :ref:`How to use
  947
+Django with Apache and mod_python <howto-deployment-modpython>`).

0 notes on commit 030c97b

Please sign in to comment.
Something went wrong with that request. Please try again.