Refs #21927 -- Added examples to urls.include() changes in 1.9 release notes.

This commit is contained in:
Tim Graham 2015-09-23 08:14:13 -04:00
parent f06ce6053c
commit 0e723ead52
1 changed files with 50 additions and 6 deletions

View File

@ -1180,13 +1180,57 @@ documentation <custom-template-loaders>`.
Passing a 3-tuple or an ``app_name`` to :func:`~django.conf.urls.include()` Passing a 3-tuple or an ``app_name`` to :func:`~django.conf.urls.include()`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The instance namespace part of passing a tuple as the first argument has been The instance namespace part of passing a tuple as an argument to ``include()``
replaced by passing the ``namespace`` argument to ``include()``. The has been replaced by passing the ``namespace`` argument to ``include()``. For
``app_name`` argument to ``include()`` has been replaced by passing a 2-tuple, example::
or passing an object or module with an ``app_name`` attribute.
If the ``app_name`` is set in this new way, the ``namespace`` argument is no polls_patterns = [
longer required. It will default to the value of ``app_name``. url(...),
]
urlpatterns = [
url(r'^polls/', include((polls_patterns, 'polls', 'author-polls'))),
]
becomes::
polls_patterns = ([
url(...),
], 'polls') # 'polls' is the app_name
urlpatterns = [
url(r'^polls/', include(polls_patterns, namespace='author-polls')),
]
The ``app_name`` argument to ``include()`` has been replaced by passing a
2-tuple (as above), or passing an object or module with an ``app_name``
attribute (as below). If the ``app_name`` is set in this new way, the
``namespace`` argument is no longer required. It will default to the value of
``app_name``. For example, the URL patterns in the tutorial are changed from:
.. snippet::
:filename: mysite/urls.py
urlpatterns = [
url(r'^polls/', include('polls.urls', namespace="polls")),
...
]
to:
.. snippet::
:filename: mysite/urls.py
urlpatterns = [
url(r'^polls/', include('polls.urls')), # 'namespace="polls"' removed
...
]
.. snippet::
:filename: polls/urls.py
app_name = 'polls' # added
urlpatterns = [...]
This change also means that the old way of including an ``AdminSite`` instance This change also means that the old way of including an ``AdminSite`` instance
is deprecated. Instead, pass ``admin.site.urls`` directly to is deprecated. Instead, pass ``admin.site.urls`` directly to