Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14627 -- Made Tutorial 3 more explicit regarding the transform…

…ations 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.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14472 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f6824840a2797ee70f5de559e27eee9b7b2207af 1 parent 63046ec
authored November 06, 2010

Showing 1 changed file with 28 additions and 5 deletions. Show diff stats Hide diff stats

  1. 33  docs/intro/tutorial03.txt
33  docs/intro/tutorial03.txt
@@ -454,6 +454,27 @@ first argument to :func:`~django.conf.urls.defaults.patterns`, like so::
454 454
 This is functionally identical to the previous formatting. It's just a bit
455 455
 tidier.
456 456
 
  457
+Since you generally don't want the prefix for one app to be applied to every
  458
+callback in your URLconf, you can concatenate multiple
  459
+:func:`~django.conf.urls.defaults.patterns`. Your full ``mysite/urls.py`` might
  460
+now look like this::
  461
+
  462
+    from django.conf.urls.defaults import *
  463
+
  464
+    from django.contrib import admin
  465
+    admin.autodiscover()
  466
+    
  467
+    urlpatterns = patterns('polls.views',
  468
+        (r'^polls/$', 'index'),
  469
+        (r'^polls/(?P<poll_id>\d+)/$', 'detail'),
  470
+        (r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
  471
+        (r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
  472
+    )
  473
+    
  474
+    urlpatterns += patterns('',
  475
+        (r'^admin/', include(admin.site.urls)),
  476
+    )
  477
+
457 478
 Decoupling the URLconfs
458 479
 =======================
459 480
 
@@ -472,18 +493,20 @@ URLs within the app directory.
472 493
 
473 494
 Copy the file ``mysite/urls.py`` to ``polls/urls.py``. Then, change
474 495
 ``mysite/urls.py`` to remove the poll-specific URLs and insert an
475  
-:func:`~django.conf.urls.defaults.include`::
  496
+:func:`~django.conf.urls.defaults.include`, leaving you with::
476 497
 
477 498
     # This also imports the include function
478 499
     from django.conf.urls.defaults import *
479  
-
480  
-    # ...
  500
+    
  501
+    from django.contrib import admin
  502
+    admin.autodiscover()
  503
+    
481 504
     urlpatterns = patterns('',
482 505
         (r'^polls/', include('polls.urls')),
483  
-        # ...
  506
+        (r'^admin/', include(admin.site.urls)),
484 507
     )
485 508
 
486  
-:func:`~django.conf.urls.defaults.include`, simply, references another URLconf.
  509
+:func:`~django.conf.urls.defaults.include` simply references another URLconf.
487 510
 Note that the regular expression doesn't have a ``$`` (end-of-string match
488 511
 character) but has the trailing slash. Whenever Django encounters
489 512
 :func:`~django.conf.urls.defaults.include`, it chops off whatever part of the

0 notes on commit f682484

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