Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #131 -- URLconfs that are 'included' now receive captured param…

…eters from parent URLconfs. Thanks for the idea, jcernelli@gmail.com

git-svn-id: http://code.djangoproject.com/svn/django/trunk@704 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c084005d5822baa6c4e6250df57ae4f5f7cd2876 1 parent 7f40671
Adrian Holovaty authored September 27, 2005
2  django/core/urlresolvers.py
@@ -66,7 +66,7 @@ def resolve(self, path):
66 66
                     tried.extend([(pattern.regex.pattern + '   ' + t) for t in e.args[0]['tried']])
67 67
                 else:
68 68
                     if sub_match:
69  
-                        return sub_match
  69
+                        return sub_match[0], dict(match.groupdict(), **sub_match[1])
70 70
                     tried.append(pattern.regex.pattern)
71 71
             raise Resolver404, {'tried': tried, 'path': new_path}
72 72
 
38  docs/url_dispatch.txt
@@ -2,7 +2,7 @@
2 2
 URL dispatcher
3 3
 ==============
4 4
 
5  
-We're fanatics about good URLs.  No ".php" or ".cgi", and certainly not any of
  5
+We're fanatics about good URLs. No ".php" or ".cgi", and certainly not any of
6 6
 that "0,2097,1-1-1928,00" nonsense. Django's URL dispatcher lets you design
7 7
 your URLs to be as pretty as the rest of your application.
8 8
 
@@ -24,10 +24,10 @@ Here's the example from that overview::
24 24
         (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/$', 'myproject.news.views.articles.article_detail'),
25 25
     )
26 26
 
27  
-You can see that the first argument to ``patterns`` is an empty string in the
28  
-above example, but that argument is actually very useful. The first argument
29  
-will be prepended to all the view functions in the urlpatterns list, so the
30  
-above example could be written more concisely as::
  27
+The first argument to ``patterns`` is an empty string in the above example, but
  28
+that argument can be useful. The first argument is prepended to all the view
  29
+functions in the urlpatterns list, so the above example could be written more
  30
+concisely as::
31 31
 
32 32
     urlpatterns = patterns('myproject.news.views.articles',
33 33
         (r'^/articles/(?P<year>\d{4})/$', 'year_archive'),
@@ -43,11 +43,11 @@ above example could be written more concisely as::
43 43
 Including other URLconfs
44 44
 ========================
45 45
 
46  
-You can also "include" other URL config modules at any point along the path.
47  
-This essentially "roots" a set of URLs below other ones.  This is most often
48  
-used for a site's "base" URLconfig; the ``ROOT_URLCONF`` setting points to a
49  
-urlconf module that will be used for the entire site. Here's the URLconf
50  
-for the `Django website`_ itself. It includes a number of other URLconfs::
  46
+You can also "include" other URLconf modules at any point along the path. This
  47
+essentially "roots" a set of URLs below other ones.  This is most often used
  48
+for a site's "base" URLconf; the ``ROOT_URLCONF`` setting points to a urlconf
  49
+module that will be used for the entire site. Here's the URLconf for the
  50
+`Django website`_ itself. It includes a number of other URLconfs::
51 51
 
52 52
     from django.conf.urls.defaults import *
53 53
 
@@ -59,6 +59,22 @@ for the `Django website`_ itself. It includes a number of other URLconfs::
59 59
         (r'',                include('django.conf.urls.flatfiles')),
60 60
     )
61 61
 
  62
+Note that an included URLconf receives any captured parameters from parent
  63
+URLconfs, so the following example is valid::
  64
+
  65
+    # In settings/urls/main.py
  66
+    urlpatterns = patterns('',
  67
+        (r'^(?P<username>\w+)/blog/', include('foo.urls.blog')),
  68
+    )
  69
+
  70
+    # In foo/urls/blog.py
  71
+    urlpatterns = patterns('foo.views'
  72
+        (r'^$', 'blog.index'),
  73
+        (r'^archive/$', 'blog.archive'),
  74
+
  75
+In the above example, the captured ``"username"`` variable is passed to the
  76
+included URLconf, as expected.
  77
+
62 78
 .. _`Django website`: http://www.djangoproject.com/
63 79
 
64 80
 Passing extra options to view functions
@@ -70,5 +86,5 @@ in URLconf tuples. This third element can be a dictionary of extra keyword
70 86
 arguments that will be passed to the view function::
71 87
 
72 88
     urlpatterns = patterns('myproject.news.views.articles',
73  
-        (r'^/articles/(?P<year>\d{4})/$', 'year_archive', {key: value, key2: value 2}),
  89
+        (r'^/articles/(?P<year>\d{4})/$', 'year_archive', {key: value, key2: value2}),
74 90
     )

0 notes on commit c084005

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