Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11439 -- Added docs on including URL patterns as an iterable. …

…Thanks to Ramiro Morales for the draft text.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11221 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ebce1b9a2b588b95e56a3719b3ac71a82834965a 1 parent 2124811
Russell Keith-Magee authored July 11, 2009

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

  1. 36  docs/topics/http/urls.txt
36  docs/topics/http/urls.txt
@@ -40,14 +40,14 @@ algorithm the system follows to determine which Python code to execute:
40 40
        this is the value of the ``ROOT_URLCONF`` setting, but if the incoming
41 41
        ``HttpRequest`` object has an attribute called ``urlconf``, its value
42 42
        will be used in place of the ``ROOT_URLCONF`` setting.
43  
-    
  43
+
44 44
     2. Django loads that Python module and looks for the variable
45 45
        ``urlpatterns``. This should be a Python list, in the format returned by
46 46
        the function ``django.conf.urls.defaults.patterns()``.
47  
-    
  47
+
48 48
     3. Django runs through each URL pattern, in order, and stops at the first
49 49
        one that matches the requested URL.
50  
-    
  50
+
51 51
     4. Once one of the regexes matches, Django imports and calls the given
52 52
        view, which is a simple Python function. The view gets passed an
53 53
        :class:`~django.http.HttpRequest` as its first argument and any values
@@ -263,8 +263,15 @@ value should suffice.
263 263
 include
264 264
 -------
265 265
 
266  
-A function that takes a full Python import path to another URLconf that should
267  
-be "included" in this place. See `Including other URLconfs`_ below.
  266
+A function that takes a full Python import path to another URLconf module that
  267
+should be "included" in this place.
  268
+
  269
+.. versionadded:: 1.1
  270
+
  271
+:meth:``include`` also accepts as an argument an iterable that returns URL
  272
+patterns.
  273
+
  274
+See `Including other URLconfs`_ below.
268 275
 
269 276
 Notes on capturing text in URLs
270 277
 ===============================
@@ -391,6 +398,25 @@ Django encounters ``include()``, it chops off whatever part of the URL matched
391 398
 up to that point and sends the remaining string to the included URLconf for
392 399
 further processing.
393 400
 
  401
+.. versionadded:: 1.1
  402
+
  403
+Another posibility is to include additional URL patterns not by specifying the
  404
+URLconf Python module defining them as the `include`_ argument but by using
  405
+directly the pattern list as returned by `patterns`_ instead. For example::
  406
+
  407
+    from django.conf.urls.defaults import *
  408
+
  409
+    extra_patterns = patterns('',
  410
+        url(r'reports/(?P<id>\d+)/$', 'credit.views.report', name='credit-reports'),
  411
+        url(r'charge/$', 'credit.views.charge', name='credit-charge'),
  412
+    )
  413
+
  414
+    urlpatterns = patterns('',
  415
+        url(r'^$',    'apps.main.views.homepage', name='site-homepage'),
  416
+        (r'^help/',   include('apps.help.urls')),
  417
+        (r'^credit/', include(extra_patterns)),
  418
+    )
  419
+
394 420
 .. _`Django Web site`: http://www.djangoproject.com/
395 421
 
396 422
 Captured parameters

0 notes on commit ebce1b9

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