mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #21927 -- Made application and instance namespaces more distinct.
Made URL application namespaces be set in the included URLconf and instance namespaces in the call to include(). Deprecated other ways to set application and instance namespaces.
This commit is contained in:
parent
39937de7e6
commit
1e82094f1b
30 changed files with 352 additions and 113 deletions
|
@ -293,15 +293,15 @@ with:
|
|||
|
||||
urlpatterns = [
|
||||
url(r'^polls/', include('polls.urls')),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^admin/', admin.site.urls),
|
||||
]
|
||||
|
||||
.. admonition:: Doesn't match what you see?
|
||||
|
||||
If you're seeing ``admin.autodiscover()`` before the definition of
|
||||
``urlpatterns``, you're probably using a version of Django that doesn't
|
||||
match this tutorial version. You'll want to either switch to the older
|
||||
tutorial or the newer Django version.
|
||||
If you're seeing ``include(admin.site.urls)`` instead of just
|
||||
``admin.site.urls``, you're probably using a version of Django that
|
||||
doesn't match this tutorial version. You'll want to either switch to the
|
||||
older tutorial or the newer Django version.
|
||||
|
||||
You have now wired an ``index`` view into the URLconf. Lets verify it's
|
||||
working, run the following command:
|
||||
|
|
|
@ -442,18 +442,20 @@ view, and so might an app on the same project that is for a blog. How does one
|
|||
make it so that Django knows which app view to create for a url when using the
|
||||
``{% url %}`` template tag?
|
||||
|
||||
The answer is to add namespaces to your root URLconf. In the ``mysite/urls.py``
|
||||
file, go ahead and change it to include namespacing:
|
||||
The answer is to add namespaces to your URLconf. In the ``polls/urls.py``
|
||||
file, go ahead and add an ``app_name`` to set the application namespace:
|
||||
|
||||
.. snippet::
|
||||
:filename: mysite/urls.py
|
||||
:filename: polls/urls.py
|
||||
|
||||
from django.conf.urls import include, url
|
||||
from django.contrib import admin
|
||||
from django.conf.urls import url
|
||||
|
||||
app_name = 'polls'
|
||||
urlpatterns = [
|
||||
url(r'^polls/', include('polls.urls', namespace="polls")),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^$', views.index, name='index'),
|
||||
url(r'^(?P<question_id>[0-9]+)/$', views.detail, name='detail'),
|
||||
url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'),
|
||||
url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),
|
||||
]
|
||||
|
||||
Now change your ``polls/index.html`` template from:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue