mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #2370 -- It's now possible to pass default URLconf arguments to include(). Added docs, as well. Thanks for the patch, martin.glueck@gmail.com
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3506 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -389,3 +389,45 @@ to pass metadata and options to views.
|
||||
|
||||
.. _generic views: http://www.djangoproject.com/documentation/generic_views/
|
||||
.. _syndication framework: http://www.djangoproject.com/documentation/syndication/
|
||||
|
||||
Passing extra options to ``include()``
|
||||
--------------------------------------
|
||||
|
||||
**New in the Django development version.**
|
||||
|
||||
Similarly, you can pass extra options to ``include()``. When you pass extra
|
||||
options to ``include()``, *each* line in the included URLconf will be passed
|
||||
the extra options.
|
||||
|
||||
For example, these two URLconf sets are functionally identical:
|
||||
|
||||
Set one::
|
||||
|
||||
# main.py
|
||||
urlpatterns = patterns('',
|
||||
(r'^blog/', include('inner'), {'blogid': 3}),
|
||||
)
|
||||
|
||||
# inner.py
|
||||
urlpatterns = patterns('',
|
||||
(r'^archive/$', 'mysite.views.archive'),
|
||||
(r'^about/$', 'mysite.views.about'),
|
||||
)
|
||||
|
||||
Set two::
|
||||
|
||||
# main.py
|
||||
urlpatterns = patterns('',
|
||||
(r'^blog/', include('inner')),
|
||||
)
|
||||
|
||||
# inner.py
|
||||
urlpatterns = patterns('',
|
||||
(r'^archive/$', 'mysite.views.archive', {'blogid': 3}),
|
||||
(r'^about/$', 'mysite.views.about', {'blogid': 3}),
|
||||
)
|
||||
|
||||
Note that extra options will *always* be passed to *every* line in the included
|
||||
URLconf, regardless of whether the line's view actually accepts those options
|
||||
as valid. For this reason, this technique is only useful if you're certain that
|
||||
every view in the the included URLconf accepts the extra options you're passing.
|
||||
|
||||
Reference in New Issue
Block a user