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:
Tim Graham 2014-04-01 20:46:34 -04:00
parent e6ced2bb08
commit d73d0e071c
117 changed files with 1180 additions and 1099 deletions

View file

@ -39,13 +39,13 @@ View
**Example urls.py**::
from django.conf.urls import patterns, url
from django.conf.urls import url
from myapp.views import MyView
urlpatterns = patterns('',
urlpatterns = [
url(r'^mine/$', MyView.as_view(), name='my-view'),
)
]
**Attributes**
@ -131,13 +131,13 @@ TemplateView
**Example urls.py**::
from django.conf.urls import patterns, url
from django.conf.urls import url
from myapp.views import HomePageView
urlpatterns = patterns('',
urlpatterns = [
url(r'^$', HomePageView.as_view(), name='home'),
)
]
**Context**
@ -192,17 +192,16 @@ RedirectView
**Example urls.py**::
from django.conf.urls import patterns, url
from django.conf.urls import url
from django.views.generic.base import RedirectView
from article.views import ArticleCounterRedirectView, ArticleDetail
urlpatterns = patterns('',
urlpatterns = [
url(r'^counter/(?P<pk>\d+)/$', ArticleCounterRedirectView.as_view(), name='article-counter'),
url(r'^details/(?P<pk>\d+)/$', ArticleDetail.as_view(), name='article-detail'),
url(r'^go-to-django/$', RedirectView.as_view(url='http://djangoproject.com'), name='go-to-django'),
)
]
**Attributes**

View file

@ -65,16 +65,16 @@ ArchiveIndexView
**Example myapp/views.py**::
from django.conf.urls import patterns, url
from django.conf.urls import url
from django.views.generic.dates import ArchiveIndexView
from myapp.models import Article
urlpatterns = patterns('',
urlpatterns = [
url(r'^archive/$',
ArchiveIndexView.as_view(model=Article, date_field="pub_date"),
name="article_archive"),
)
]
**Example myapp/article_archive.html**:
@ -166,15 +166,15 @@ YearArchiveView
**Example myapp/urls.py**::
from django.conf.urls import patterns, url
from django.conf.urls import url
from myapp.views import ArticleYearArchiveView
urlpatterns = patterns('',
urlpatterns = [
url(r'^(?P<year>\d{4})/$',
ArticleYearArchiveView.as_view(),
name="article_year_archive"),
)
]
**Example myapp/article_archive_year.html**:
@ -261,11 +261,11 @@ MonthArchiveView
**Example myapp/urls.py**::
from django.conf.urls import patterns, url
from django.conf.urls import url
from myapp.views import ArticleMonthArchiveView
urlpatterns = patterns('',
urlpatterns = [
# Example: /2012/aug/
url(r'^(?P<year>\d{4})/(?P<month>[-\w]+)/$',
ArticleMonthArchiveView.as_view(),
@ -274,7 +274,7 @@ MonthArchiveView
url(r'^(?P<year>\d{4})/(?P<month>\d+)/$',
ArticleMonthArchiveView.as_view(month_format='%m'),
name="archive_month_numeric"),
)
]
**Example myapp/article_archive_month.html**:
@ -355,16 +355,16 @@ WeekArchiveView
**Example myapp/urls.py**::
from django.conf.urls import patterns, url
from django.conf.urls import url
from myapp.views import ArticleWeekArchiveView
urlpatterns = patterns('',
urlpatterns = [
# Example: /2012/week/23/
url(r'^(?P<year>\d{4})/week/(?P<week>\d+)/$',
ArticleWeekArchiveView.as_view(),
name="archive_week"),
)
]
**Example myapp/article_archive_week.html**:
@ -469,16 +469,16 @@ DayArchiveView
**Example myapp/urls.py**::
from django.conf.urls import patterns, url
from django.conf.urls import url
from myapp.views import ArticleDayArchiveView
urlpatterns = patterns('',
urlpatterns = [
# Example: /2012/nov/10/
url(r'^(?P<year>\d{4})/(?P<month>[-\w]+)/(?P<day>\d+)/$',
ArticleDayArchiveView.as_view(),
name="archive_day"),
)
]
**Example myapp/article_archive_day.html**:
@ -543,15 +543,15 @@ TodayArchiveView
**Example myapp/urls.py**::
from django.conf.urls import patterns, url
from django.conf.urls import url
from myapp.views import ArticleTodayArchiveView
urlpatterns = patterns('',
urlpatterns = [
url(r'^today/$',
ArticleTodayArchiveView.as_view(),
name="archive_today"),
)
]
.. admonition:: Where is the example template for ``TodayArchiveView``?
@ -593,14 +593,14 @@ DateDetailView
**Example myapp/urls.py**::
from django.conf.urls import patterns, url
from django.conf.urls import url
from django.views.generic.dates import DateDetailView
urlpatterns = patterns('',
urlpatterns = [
url(r'^(?P<year>\d+)/(?P<month>[-\w]+)/(?P<day>\d+)/(?P<pk>\d+)/$',
DateDetailView.as_view(model=Article, date_field="pub_date"),
name="archive_date_detail"),
)
]
**Example myapp/article_detail.html**:

View file

@ -54,13 +54,13 @@ DetailView
**Example myapp/urls.py**::
from django.conf.urls import patterns, url
from django.conf.urls import url
from article.views import ArticleDetailView
urlpatterns = patterns('',
urlpatterns = [
url(r'^(?P<slug>[-_\w]+)/$', ArticleDetailView.as_view(), name='article-detail'),
)
]
**Example myapp/article_detail.html**:
@ -123,13 +123,13 @@ ListView
**Example myapp/urls.py**::
from django.conf.urls import patterns, url
from django.conf.urls import url
from article.views import ArticleListView
urlpatterns = patterns('',
urlpatterns = [
url(r'^$', ArticleListView.as_view(), name='article-list'),
)
]
**Example myapp/article_list.html**:

View file

@ -25,9 +25,9 @@ a thread-safe operation).
A class-based view is deployed into a URL pattern using the
:meth:`~django.views.generic.base.View.as_view()` classmethod::
urlpatterns = patterns('',
(r'^view/$', MyView.as_view(size=42)),
)
urlpatterns = [
url(r'^view/$', MyView.as_view(size=42)),
]
.. admonition:: Thread safety with view arguments