summaryrefslogtreecommitdiff
path: root/docs/ref/class-based-views
diff options
context:
space:
mode:
authorSjoerd Job Postmus <sjoerdjob@sjec.nl>2016-10-20 19:29:04 +0200
committerTim Graham <timograham@gmail.com>2017-09-20 18:04:42 -0400
commitdf41b5a05d4e00e80e73afe629072e37873e767a (patch)
treebaaf71ae695e2d3af604ea0d663284cb406c71e4 /docs/ref/class-based-views
parentc4c128d67c7dc2830631c6859a204c9d259f1fb1 (diff)
Fixed #28593 -- Added a simplified URL routing syntax per DEP 0201.
Thanks Aymeric Augustin for shepherding the DEP and patch review. Thanks Marten Kenbeek and Tim Graham for contributing to the code. Thanks Tom Christie, Shai Berger, and Tim Graham for the docs.
Diffstat (limited to 'docs/ref/class-based-views')
-rw-r--r--docs/ref/class-based-views/base.txt16
-rw-r--r--docs/ref/class-based-views/generic-date-based.txt64
-rw-r--r--docs/ref/class-based-views/generic-display.txt8
-rw-r--r--docs/ref/class-based-views/index.txt2
-rw-r--r--docs/ref/class-based-views/mixins-multiple-object.txt2
5 files changed, 46 insertions, 46 deletions
diff --git a/docs/ref/class-based-views/base.txt b/docs/ref/class-based-views/base.txt
index 6230f1181e..6ef72176c3 100644
--- a/docs/ref/class-based-views/base.txt
+++ b/docs/ref/class-based-views/base.txt
@@ -40,12 +40,12 @@ MRO is an acronym for Method Resolution Order.
**Example urls.py**::
- from django.conf.urls import url
+ from django.urls import path
from myapp.views import MyView
urlpatterns = [
- url(r'^mine/$', MyView.as_view(), name='my-view'),
+ path('mine/', MyView.as_view(), name='my-view'),
]
**Attributes**
@@ -144,12 +144,12 @@ MRO is an acronym for Method Resolution Order.
**Example urls.py**::
- from django.conf.urls import url
+ from django.urls import path
from myapp.views import HomePageView
urlpatterns = [
- url(r'^$', HomePageView.as_view(), name='home'),
+ path('', HomePageView.as_view(), name='home'),
]
**Context**
@@ -208,15 +208,15 @@ MRO is an acronym for Method Resolution Order.
**Example urls.py**::
- from django.conf.urls import url
+ from django.urls import path
from django.views.generic.base import RedirectView
from article.views import ArticleCounterRedirectView, ArticleDetail
urlpatterns = [
- url(r'^counter/(?P<pk>[0-9]+)/$', ArticleCounterRedirectView.as_view(), name='article-counter'),
- url(r'^details/(?P<pk>[0-9]+)/$', ArticleDetail.as_view(), name='article-detail'),
- url(r'^go-to-django/$', RedirectView.as_view(url='https://djangoproject.com'), name='go-to-django'),
+ path('counter/<int:pk>/', ArticleCounterRedirectView.as_view(), name='article-counter'),
+ path('details/<int:pk>/', ArticleDetail.as_view(), name='article-detail'),
+ path('go-to-django/', RedirectView.as_view(url='https://djangoproject.com'), name='go-to-django'),
]
**Attributes**
diff --git a/docs/ref/class-based-views/generic-date-based.txt b/docs/ref/class-based-views/generic-date-based.txt
index 7b50d099ba..a42896c058 100644
--- a/docs/ref/class-based-views/generic-date-based.txt
+++ b/docs/ref/class-based-views/generic-date-based.txt
@@ -63,15 +63,15 @@ views for displaying drilldown pages for date-based data.
**Example myapp/urls.py**::
- from django.conf.urls import url
+ from django.urls import path
from django.views.generic.dates import ArchiveIndexView
from myapp.models import Article
urlpatterns = [
- url(r'^archive/$',
- ArchiveIndexView.as_view(model=Article, date_field="pub_date"),
- name="article_archive"),
+ path('archive/',
+ ArchiveIndexView.as_view(model=Article, date_field="pub_date"),
+ name="article_archive"),
]
**Example myapp/article_archive.html**:
@@ -162,14 +162,14 @@ views for displaying drilldown pages for date-based data.
**Example myapp/urls.py**::
- from django.conf.urls import url
+ from django.urls import path
from myapp.views import ArticleYearArchiveView
urlpatterns = [
- url(r'^(?P<year>[0-9]{4})/$',
- ArticleYearArchiveView.as_view(),
- name="article_year_archive"),
+ path('<int:year>/',
+ ArticleYearArchiveView.as_view(),
+ name="article_year_archive"),
]
**Example myapp/article_archive_year.html**:
@@ -254,19 +254,19 @@ views for displaying drilldown pages for date-based data.
**Example myapp/urls.py**::
- from django.conf.urls import url
+ from django.urls import path
from myapp.views import ArticleMonthArchiveView
urlpatterns = [
- # Example: /2012/aug/
- url(r'^(?P<year>[0-9]{4})/(?P<month>[-\w]+)/$',
- ArticleMonthArchiveView.as_view(),
- name="archive_month"),
# Example: /2012/08/
- url(r'^(?P<year>[0-9]{4})/(?P<month>[0-9]+)/$',
- ArticleMonthArchiveView.as_view(month_format='%m'),
- name="archive_month_numeric"),
+ path('<int:year>/<int:month>/',
+ ArticleMonthArchiveView.as_view(month_format='%m'),
+ name="archive_month_numeric"),
+ # Example: /2012/aug/
+ path('<int:year>/<str:month>/',
+ ArticleMonthArchiveView.as_view(),
+ name="archive_month"),
]
**Example myapp/article_archive_month.html**:
@@ -356,15 +356,15 @@ views for displaying drilldown pages for date-based data.
**Example myapp/urls.py**::
- from django.conf.urls import url
+ from django.urls import path
from myapp.views import ArticleWeekArchiveView
urlpatterns = [
# Example: /2012/week/23/
- url(r'^(?P<year>[0-9]{4})/week/(?P<week>[0-9]+)/$',
- ArticleWeekArchiveView.as_view(),
- name="archive_week"),
+ path('<int:year>/week/<int:week>/',
+ ArticleWeekArchiveView.as_view(),
+ name="archive_week"),
]
**Example myapp/article_archive_week.html**:
@@ -468,15 +468,15 @@ views for displaying drilldown pages for date-based data.
**Example myapp/urls.py**::
- from django.conf.urls import url
+ from django.urls import path
from myapp.views import ArticleDayArchiveView
urlpatterns = [
# Example: /2012/nov/10/
- url(r'^(?P<year>[0-9]{4})/(?P<month>[-\w]+)/(?P<day>[0-9]+)/$',
- ArticleDayArchiveView.as_view(),
- name="archive_day"),
+ path('<int:year>/<str:month>/<int:day>/',
+ ArticleDayArchiveView.as_view(),
+ name="archive_day"),
]
**Example myapp/article_archive_day.html**:
@@ -541,14 +541,14 @@ views for displaying drilldown pages for date-based data.
**Example myapp/urls.py**::
- from django.conf.urls import url
+ from django.urls import path
from myapp.views import ArticleTodayArchiveView
urlpatterns = [
- url(r'^today/$',
- ArticleTodayArchiveView.as_view(),
- name="archive_today"),
+ path('today/',
+ ArticleTodayArchiveView.as_view(),
+ name="archive_today"),
]
.. admonition:: Where is the example template for ``TodayArchiveView``?
@@ -591,13 +591,13 @@ views for displaying drilldown pages for date-based data.
**Example myapp/urls.py**::
- from django.conf.urls import url
+ from django.urls import path
from django.views.generic.dates import DateDetailView
urlpatterns = [
- url(r'^(?P<year>[0-9]{4})/(?P<month>[-\w]+)/(?P<day>[0-9]+)/(?P<pk>[0-9]+)/$',
- DateDetailView.as_view(model=Article, date_field="pub_date"),
- name="archive_date_detail"),
+ path('<int:year>/<str:month>/<int:day>/<int:pk>/',
+ DateDetailView.as_view(model=Article, date_field="pub_date"),
+ name="archive_date_detail"),
]
**Example myapp/article_detail.html**:
diff --git a/docs/ref/class-based-views/generic-display.txt b/docs/ref/class-based-views/generic-display.txt
index 70da1803d6..16975bdbea 100644
--- a/docs/ref/class-based-views/generic-display.txt
+++ b/docs/ref/class-based-views/generic-display.txt
@@ -54,12 +54,12 @@ many projects they are typically the most commonly used views.
**Example myapp/urls.py**::
- from django.conf.urls import url
+ from django.urls import path
from article.views import ArticleDetailView
urlpatterns = [
- url(r'^(?P<slug>[-\w]+)/$', ArticleDetailView.as_view(), name='article-detail'),
+ path('<slug>/', ArticleDetailView.as_view(), name='article-detail'),
]
**Example myapp/article_detail.html**:
@@ -123,12 +123,12 @@ many projects they are typically the most commonly used views.
**Example myapp/urls.py**::
- from django.conf.urls import url
+ from django.urls import path
from article.views import ArticleListView
urlpatterns = [
- url(r'^$', ArticleListView.as_view(), name='article-list'),
+ path('', ArticleListView.as_view(), name='article-list'),
]
**Example myapp/article_list.html**:
diff --git a/docs/ref/class-based-views/index.txt b/docs/ref/class-based-views/index.txt
index 17bd5315ff..5187000385 100644
--- a/docs/ref/class-based-views/index.txt
+++ b/docs/ref/class-based-views/index.txt
@@ -26,7 +26,7 @@ A class-based view is deployed into a URL pattern using the
:meth:`~django.views.generic.base.View.as_view()` classmethod::
urlpatterns = [
- url(r'^view/$', MyView.as_view(size=42)),
+ path('view/', MyView.as_view(size=42)),
]
.. admonition:: Thread safety with view arguments
diff --git a/docs/ref/class-based-views/mixins-multiple-object.txt b/docs/ref/class-based-views/mixins-multiple-object.txt
index 58260391a8..8f6fcb8d48 100644
--- a/docs/ref/class-based-views/mixins-multiple-object.txt
+++ b/docs/ref/class-based-views/mixins-multiple-object.txt
@@ -15,7 +15,7 @@ Multiple object mixins
* Use the ``page`` parameter in the URLconf. For example, this is what
your URLconf might look like::
- url(r'^objects/page(?P<page>[0-9]+)/$', PaginatedView.as_view()),
+ path('objects/page<int:page>/', PaginatedView.as_view()),
* Pass the page number via the ``page`` query-string parameter. For
example, a URL would look like this::