1
0
mirror of https://github.com/django/django.git synced 2025-07-05 18:29:11 +00:00

[1.2.X] Fixes #14743 - Add sphinx links and other cleanups to topics/http/urls.txt. Thanks adamv for the patch.

Backport of applicable portions of 14705 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14706 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Timo Graham 2010-11-26 13:27:28 +00:00
parent 1c68437d1d
commit 4b752d6490

View File

@ -37,14 +37,14 @@ When a user requests a page from your Django-powered site, this is the
algorithm the system follows to determine which Python code to execute: algorithm the system follows to determine which Python code to execute:
1. Django determines the root URLconf module to use. Ordinarily, 1. Django determines the root URLconf module to use. Ordinarily,
this is the value of the ``ROOT_URLCONF`` setting, but if the incoming this is the value of the :setting:`ROOT_URLCONF` setting, but if the incoming
``HttpRequest`` object has an attribute called ``urlconf`` (set by ``HttpRequest`` object has an attribute called ``urlconf`` (set by
middleware :ref:`request processing <request-middleware>`), its value middleware :ref:`request processing <request-middleware>`), its value
will be used in place of the ``ROOT_URLCONF`` setting. will be used in place of the :setting:`ROOT_URLCONF` setting.
2. Django loads that Python module and looks for the variable 2. Django loads that Python module and looks for the variable
``urlpatterns``. This should be a Python list, in the format returned by ``urlpatterns``. This should be a Python list, in the format returned by
the function ``django.conf.urls.defaults.patterns()``. the function :func:`django.conf.urls.defaults.patterns`.
3. Django runs through each URL pattern, in order, and stops at the first 3. Django runs through each URL pattern, in order, and stops at the first
one that matches the requested URL. one that matches the requested URL.
@ -174,12 +174,14 @@ Syntax of the urlpatterns variable
================================== ==================================
``urlpatterns`` should be a Python list, in the format returned by the function ``urlpatterns`` should be a Python list, in the format returned by the function
``django.conf.urls.defaults.patterns()``. Always use ``patterns()`` to create :func:`django.conf.urls.defaults.patterns`. Always use ``patterns()`` to create
the ``urlpatterns`` variable. the ``urlpatterns`` variable.
Convention is to use ``from django.conf.urls.defaults import *`` at the top of Convention is to use ``from django.conf.urls.defaults import *`` at the top of
your URLconf. This gives your module access to these objects: your URLconf. This gives your module access to these objects:
.. module:: django.conf.urls.defaults
patterns patterns
-------- --------
@ -436,10 +438,11 @@ directly the pattern list as returned by `patterns`_ instead. For example::
This approach can be seen in use when you deploy an instance of the Django This approach can be seen in use when you deploy an instance of the Django
Admin application. The Django Admin is deployed as instances of a Admin application. The Django Admin is deployed as instances of a
:class:`AdminSite`; each :class:`AdminSite` instance has an attribute :class:`~django.contrib.admin.AdminSite`; each
``urls`` that returns the url patterns available to that instance. It is this :class:`~django.contrib.admin.AdminSite` instance has an attribute ``urls``
attribute that you ``include()`` into your projects ``urlpatterns`` when you that returns the url patterns available to that instance. It is this attribute
deploy the admin instance. that you ``include()`` into your projects ``urlpatterns`` when you deploy the
admin instance.
.. _`Django Web site`: http://www.djangoproject.com/ .. _`Django Web site`: http://www.djangoproject.com/
@ -507,9 +510,9 @@ a 3-tuple containing::
This will include the nominated URL patterns into the given application and This will include the nominated URL patterns into the given application and
instance namespace. For example, the ``urls`` attribute of Django's instance namespace. For example, the ``urls`` attribute of Django's
:class:`AdminSite` object returns a 3-tuple that contains all the patterns in :class:`~django.contrib.admin.AdminSite` object returns a 3-tuple that contains
an admin site, plus the name of the admin instance, and the application all the patterns in an admin site, plus the name of the admin instance, and the
namespace ``admin``. application namespace ``admin``.
Once you have defined namespaced URLs, you can reverse them. For details on Once you have defined namespaced URLs, you can reverse them. For details on
reversing namespaced urls, see the documentation on :ref:`reversing namespaced reversing namespaced urls, see the documentation on :ref:`reversing namespaced
@ -830,15 +833,16 @@ URL paths to the corresponding view functions. It has the following signature:
.. function:: resolve(path, urlconf=None) .. function:: resolve(path, urlconf=None)
``path`` is the URL path you want to resolve. As with ``reverse()`` above, you ``path`` is the URL path you want to resolve. As with
don't need to worry about the ``urlconf`` parameter. The function returns the :func:`~django.core.urlresolvers.reverse`, you don't need to
triple (view function, arguments, keyword arguments). worry about the ``urlconf`` parameter. The function returns
the triple (view function, arguments, keyword arguments).
If the URL does not resolve, the function raises an If the URL does not resolve, the function raises an
:class:`~django.http.Http404` exception. :class:`~django.http.Http404` exception.
For example, it can be used for testing if a view would raise a ``Http404`` For example, it can be used for testing if a view would raise a ``Http404``
error before redirecting to it:: error before redirecting to it:
from urlparse import urlparse from urlparse import urlparse
from django.core.urlresolvers import resolve from django.core.urlresolvers import resolve