diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-09-27 04:24:19 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-09-27 04:24:19 +0000 |
| commit | c084005d5822baa6c4e6250df57ae4f5f7cd2876 (patch) | |
| tree | ed4f94423f848198e4363fee2debb20ac2c9b5eb /docs/url_dispatch.txt | |
| parent | 7f4067100cd6767f37b8f50c553dacbd738b8771 (diff) | |
Fixed #131 -- URLconfs that are 'included' now receive captured parameters 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
Diffstat (limited to 'docs/url_dispatch.txt')
| -rw-r--r-- | docs/url_dispatch.txt | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/docs/url_dispatch.txt b/docs/url_dispatch.txt index c4603e69ac..3a3feea8be 100644 --- a/docs/url_dispatch.txt +++ b/docs/url_dispatch.txt @@ -2,7 +2,7 @@ URL dispatcher ============== -We're fanatics about good URLs. No ".php" or ".cgi", and certainly not any of +We're fanatics about good URLs. No ".php" or ".cgi", and certainly not any of that "0,2097,1-1-1928,00" nonsense. Django's URL dispatcher lets you design your URLs to be as pretty as the rest of your application. @@ -24,10 +24,10 @@ Here's the example from that overview:: (r'^/articles/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d+)/$', 'myproject.news.views.articles.article_detail'), ) -You can see that the first argument to ``patterns`` is an empty string in the -above example, but that argument is actually very useful. The first argument -will be prepended to all the view functions in the urlpatterns list, so the -above example could be written more concisely as:: +The first argument to ``patterns`` is an empty string in the above example, but +that argument can be useful. The first argument is prepended to all the view +functions in the urlpatterns list, so the above example could be written more +concisely as:: urlpatterns = patterns('myproject.news.views.articles', (r'^/articles/(?P<year>\d{4})/$', 'year_archive'), @@ -43,11 +43,11 @@ above example could be written more concisely as:: Including other URLconfs ======================== -You can also "include" other URL config modules at any point along the path. -This essentially "roots" a set of URLs below other ones. This is most often -used for a site's "base" URLconfig; the ``ROOT_URLCONF`` setting points to a -urlconf module that will be used for the entire site. Here's the URLconf -for the `Django website`_ itself. It includes a number of other URLconfs:: +You can also "include" other URLconf modules at any point along the path. This +essentially "roots" a set of URLs below other ones. This is most often used +for a site's "base" URLconf; the ``ROOT_URLCONF`` setting points to a urlconf +module that will be used for the entire site. Here's the URLconf for the +`Django website`_ itself. It includes a number of other URLconfs:: from django.conf.urls.defaults import * @@ -59,6 +59,22 @@ for the `Django website`_ itself. It includes a number of other URLconfs:: (r'', include('django.conf.urls.flatfiles')), ) +Note that an included URLconf receives any captured parameters from parent +URLconfs, so the following example is valid:: + + # In settings/urls/main.py + urlpatterns = patterns('', + (r'^(?P<username>\w+)/blog/', include('foo.urls.blog')), + ) + + # In foo/urls/blog.py + urlpatterns = patterns('foo.views' + (r'^$', 'blog.index'), + (r'^archive/$', 'blog.archive'), + +In the above example, the captured ``"username"`` variable is passed to the +included URLconf, as expected. + .. _`Django website`: http://www.djangoproject.com/ Passing extra options to view functions @@ -70,5 +86,5 @@ in URLconf tuples. This third element can be a dictionary of extra keyword arguments that will be passed to the view function:: urlpatterns = patterns('myproject.news.views.articles', - (r'^/articles/(?P<year>\d{4})/$', 'year_archive', {key: value, key2: value 2}), + (r'^/articles/(?P<year>\d{4})/$', 'year_archive', {key: value, key2: value2}), ) |
