summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorGabriel Hurley <gabehr@gmail.com>2010-11-06 10:09:35 +0000
committerGabriel Hurley <gabehr@gmail.com>2010-11-06 10:09:35 +0000
commit24ce5033c835b76556893001758ef7e12f305373 (patch)
treeeb675e312c6a7e69eddb857bc97092c13f265e73 /docs
parent1423593e8fe21072de841183cd76a667b6523ed1 (diff)
[1.2.X] Fixed #14627 -- Made Tutorial 3 more explicit regarding the transformations the URLconf undergoes in the final two sections, and gave an example of concatenating two patterns() in the process. Thanks to filmer for the report.
Backport of [14472] from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14473 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/intro/tutorial03.txt33
1 files changed, 28 insertions, 5 deletions
diff --git a/docs/intro/tutorial03.txt b/docs/intro/tutorial03.txt
index 5b2bf0ccec..8f6061a14e 100644
--- a/docs/intro/tutorial03.txt
+++ b/docs/intro/tutorial03.txt
@@ -454,6 +454,27 @@ first argument to :func:`~django.conf.urls.defaults.patterns`, like so::
This is functionally identical to the previous formatting. It's just a bit
tidier.
+Since you generally don't want the prefix for one app to be applied to every
+callback in your URLconf, you can concatenate multiple
+:func:`~django.conf.urls.defaults.patterns`. Your full ``mysite/urls.py`` might
+now look like this::
+
+ from django.conf.urls.defaults import *
+
+ from django.contrib import admin
+ admin.autodiscover()
+
+ urlpatterns = patterns('polls.views',
+ (r'^polls/$', 'index'),
+ (r'^polls/(?P<poll_id>\d+)/$', 'detail'),
+ (r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
+ (r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
+ )
+
+ urlpatterns += patterns('',
+ (r'^admin/', include(admin.site.urls)),
+ )
+
Decoupling the URLconfs
=======================
@@ -472,18 +493,20 @@ URLs within the app directory.
Copy the file ``mysite/urls.py`` to ``polls/urls.py``. Then, change
``mysite/urls.py`` to remove the poll-specific URLs and insert an
-:func:`~django.conf.urls.defaults.include`::
+:func:`~django.conf.urls.defaults.include`, leaving you with::
# This also imports the include function
from django.conf.urls.defaults import *
-
- # ...
+
+ from django.contrib import admin
+ admin.autodiscover()
+
urlpatterns = patterns('',
(r'^polls/', include('polls.urls')),
- # ...
+ (r'^admin/', include(admin.site.urls)),
)
-:func:`~django.conf.urls.defaults.include`, simply, references another URLconf.
+:func:`~django.conf.urls.defaults.include` simply references another URLconf.
Note that the regular expression doesn't have a ``$`` (end-of-string match
character) but has the trailing slash. Whenever Django encounters
:func:`~django.conf.urls.defaults.include`, it chops off whatever part of the