mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #22218 -- Deprecated django.conf.urls.patterns.
Thanks Carl Meyer for the suggestion and Alex Gaynor and Carl for reviews.
This commit is contained in:
@@ -184,13 +184,13 @@ to decouple URLs from Python code.
|
||||
Here's what a URLconf might look like for the ``Reporter``/``Article``
|
||||
example above::
|
||||
|
||||
from django.conf.urls import patterns
|
||||
from django.conf.urls import url
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^articles/(\d{4})/$', 'news.views.year_archive'),
|
||||
(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
|
||||
(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'),
|
||||
)
|
||||
urlpatterns = [
|
||||
url(r'^articles/(\d{4})/$', 'news.views.year_archive'),
|
||||
url(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
|
||||
url(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'),
|
||||
]
|
||||
|
||||
The code above maps URLs, as simple `regular expressions`_, to the location of
|
||||
Python callback functions ("views"). The regular expressions use parenthesis to
|
||||
|
||||
@@ -92,13 +92,13 @@ In the ``polls/urls.py`` file include the following code:
|
||||
.. snippet::
|
||||
:filename: polls/urls.py
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
from django.conf.urls import url
|
||||
|
||||
from polls import views
|
||||
|
||||
urlpatterns = patterns('',
|
||||
urlpatterns = [
|
||||
url(r'^$', views.index, name='index')
|
||||
)
|
||||
]
|
||||
|
||||
The next step is to point the root URLconf at the ``polls.urls`` module. In
|
||||
``mysite/urls.py`` insert an :func:`~django.conf.urls.include`, leaving you
|
||||
@@ -107,13 +107,13 @@ with:
|
||||
.. snippet::
|
||||
:filename: mysite/urls.py
|
||||
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.conf.urls import include, url
|
||||
from django.contrib import admin
|
||||
|
||||
urlpatterns = patterns('',
|
||||
urlpatterns = [
|
||||
url(r'^polls/', include('polls.urls')),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
)
|
||||
]
|
||||
|
||||
.. admonition:: Doesn't match what you see?
|
||||
|
||||
@@ -207,11 +207,11 @@ Wire these new views into the ``polls.urls`` module by adding the following
|
||||
.. snippet::
|
||||
:filename: polls/urls.py
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
from django.conf.urls import url
|
||||
|
||||
from polls import views
|
||||
|
||||
urlpatterns = patterns('',
|
||||
urlpatterns = [
|
||||
# ex: /polls/
|
||||
url(r'^$', views.index, name='index'),
|
||||
# ex: /polls/5/
|
||||
@@ -220,7 +220,7 @@ Wire these new views into the ``polls.urls`` module by adding the following
|
||||
url(r'^(?P<question_id>\d+)/results/$', views.results, name='results'),
|
||||
# ex: /polls/5/vote/
|
||||
url(r'^(?P<question_id>\d+)/vote/$', views.vote, name='vote'),
|
||||
)
|
||||
]
|
||||
|
||||
Take a look in your browser, at "/polls/34/". It'll run the ``detail()``
|
||||
method and display whatever ID you provide in the URL. Try
|
||||
@@ -583,13 +583,13 @@ it to include namespacing:
|
||||
.. snippet::
|
||||
:filename: mysite/urls.py
|
||||
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.conf.urls import include, url
|
||||
from django.contrib import admin
|
||||
|
||||
urlpatterns = patterns('',
|
||||
urlpatterns = [
|
||||
url(r'^polls/', include('polls.urls', namespace="polls")),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
)
|
||||
]
|
||||
|
||||
Now change your ``polls/index.html`` template from:
|
||||
|
||||
|
||||
@@ -222,16 +222,16 @@ First, open the ``polls/urls.py`` URLconf and change it like so:
|
||||
.. snippet::
|
||||
:filename: polls/urls.py
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
from django.conf.urls import url
|
||||
|
||||
from polls import views
|
||||
|
||||
urlpatterns = patterns('',
|
||||
urlpatterns = [
|
||||
url(r'^$', views.IndexView.as_view(), name='index'),
|
||||
url(r'^(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail'),
|
||||
url(r'^(?P<pk>\d+)/results/$', views.ResultsView.as_view(), name='results'),
|
||||
url(r'^(?P<question_id>\d+)/vote/$', views.vote, name='vote'),
|
||||
)
|
||||
]
|
||||
|
||||
Amend views
|
||||
-----------
|
||||
|
||||
Reference in New Issue
Block a user