summaryrefslogtreecommitdiff
path: root/docs/topics/class-based-views
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-04-01 20:46:34 -0400
committerTim Graham <timograham@gmail.com>2014-04-03 07:28:10 -0400
commitd73d0e071c1b4c86d57994a0ab55a74cfe80cdf5 (patch)
treef36eebaf1cdd8bd07503b3a538e7d875ff8d29b4 /docs/topics/class-based-views
parente6ced2bb086396b57601d04ad5b3ba347d1eb785 (diff)
downloaddjango-d73d0e071c1b4c86d57994a0ab55a74cfe80cdf5.tar.gz
Fixed #22218 -- Deprecated django.conf.urls.patterns.
Thanks Carl Meyer for the suggestion and Alex Gaynor and Carl for reviews.
Diffstat (limited to 'docs/topics/class-based-views')
-rw-r--r--docs/topics/class-based-views/generic-display.txt20
-rw-r--r--docs/topics/class-based-views/generic-editing.txt6
-rw-r--r--docs/topics/class-based-views/index.txt24
-rw-r--r--docs/topics/class-based-views/intro.txt22
-rw-r--r--docs/topics/class-based-views/mixins.txt6
5 files changed, 39 insertions, 39 deletions
diff --git a/docs/topics/class-based-views/generic-display.txt b/docs/topics/class-based-views/generic-display.txt
index 9c5527dac5..98d2b79d32 100644
--- a/docs/topics/class-based-views/generic-display.txt
+++ b/docs/topics/class-based-views/generic-display.txt
@@ -119,12 +119,12 @@ Now we need to define a view::
Finally hook that view into your urls::
# urls.py
- from django.conf.urls import patterns, url
+ from django.conf.urls import url
from books.views import PublisherList
- urlpatterns = patterns('',
+ urlpatterns = [
url(r'^publishers/$', PublisherList.as_view()),
- )
+ ]
That's all the Python code we need to write. We still need to write a template,
however. We could explicitly tell the view which template to use by adding a
@@ -330,12 +330,12 @@ various useful things are stored on ``self``; as well as the request
Here, we have a URLconf with a single captured group::
# urls.py
- from django.conf.urls import patterns
+ from django.conf.urls import url
from books.views import PublisherBookList
- urlpatterns = patterns('',
- (r'^books/([\w-]+)/$', PublisherBookList.as_view()),
- )
+ urlpatterns = [
+ url(r'^books/([\w-]+)/$', PublisherBookList.as_view()),
+ ]
Next, we'll write the ``PublisherBookList`` view itself::
@@ -396,13 +396,13 @@ updated.
First, we'd need to add an author detail bit in the URLconf to point to a
custom view::
- from django.conf.urls import patterns, url
+ from django.conf.urls import url
from books.views import AuthorDetailView
- urlpatterns = patterns('',
+ urlpatterns = [
#...
url(r'^authors/(?P<pk>\d+)/$', AuthorDetailView.as_view(), name='author-detail'),
- )
+ ]
Then we'd write our new view -- ``get_object`` is the method that retrieves the
object -- so we simply override it and wrap the call::
diff --git a/docs/topics/class-based-views/generic-editing.txt b/docs/topics/class-based-views/generic-editing.txt
index 44680148ab..2587c9426d 100644
--- a/docs/topics/class-based-views/generic-editing.txt
+++ b/docs/topics/class-based-views/generic-editing.txt
@@ -141,15 +141,15 @@ an :exc:`~django.core.exceptions.ImproperlyConfigured` exception if it's not.
Finally, we hook these new views into the URLconf::
# urls.py
- from django.conf.urls import patterns, url
+ from django.conf.urls import url
from myapp.views import AuthorCreate, AuthorUpdate, AuthorDelete
- urlpatterns = patterns('',
+ urlpatterns = [
# ...
url(r'author/add/$', AuthorCreate.as_view(), name='author_add'),
url(r'author/(?P<pk>\d+)/$', AuthorUpdate.as_view(), name='author_update'),
url(r'author/(?P<pk>\d+)/delete/$', AuthorDelete.as_view(), name='author_delete'),
- )
+ ]
.. note::
diff --git a/docs/topics/class-based-views/index.txt b/docs/topics/class-based-views/index.txt
index 84e4597842..dc77f04721 100644
--- a/docs/topics/class-based-views/index.txt
+++ b/docs/topics/class-based-views/index.txt
@@ -38,12 +38,12 @@ URLconf. If you're only changing a few simple attributes on a class-based view,
you can simply pass them into the
:meth:`~django.views.generic.base.View.as_view` method call itself::
- from django.conf.urls import patterns
+ from django.conf.urls import url
from django.views.generic import TemplateView
- urlpatterns = patterns('',
- (r'^about/', TemplateView.as_view(template_name="about.html")),
- )
+ urlpatterns = [
+ url(r'^about/', TemplateView.as_view(template_name="about.html")),
+ ]
Any arguments passed to :meth:`~django.views.generic.base.View.as_view` will
override attributes set on the class. In this example, we set ``template_name``
@@ -75,12 +75,12 @@ class method instead, which provides a function-like entry to class-based
views::
# urls.py
- from django.conf.urls import patterns
+ from django.conf.urls import url
from some_app.views import AboutView
- urlpatterns = patterns('',
- (r'^about/', AboutView.as_view()),
- )
+ urlpatterns = [
+ url(r'^about/', AboutView.as_view()),
+ ]
For more information on how to use the built in generic views, consult the next
@@ -100,12 +100,12 @@ preferable to ask the API when the most recent book was published.
We map the URL to book list view in the URLconf::
- from django.conf.urls import patterns
+ from django.conf.urls import url
from books.views import BookListView
- urlpatterns = patterns('',
- (r'^books/$', BookListView.as_view()),
- )
+ urlpatterns = [
+ url(r'^books/$', BookListView.as_view()),
+ ]
And the view::
diff --git a/docs/topics/class-based-views/intro.txt b/docs/topics/class-based-views/intro.txt
index dbd7a83a31..53f32198c6 100644
--- a/docs/topics/class-based-views/intro.txt
+++ b/docs/topics/class-based-views/intro.txt
@@ -89,12 +89,12 @@ request to a matching method if one is defined, or raises
:class:`~django.http.HttpResponseNotAllowed` if not::
# urls.py
- from django.conf.urls import patterns
+ from django.conf.urls import url
from myapp.views import MyView
- urlpatterns = patterns('',
- (r'^about/', MyView.as_view()),
- )
+ urlpatterns = [
+ url(r'^about/', MyView.as_view()),
+ ]
It is worth noting that what your method returns is identical to what you
@@ -129,9 +129,9 @@ You can override that in a subclass::
Another option is to configure class attributes as keyword arguments to the
:meth:`~django.views.generic.base.View.as_view` call in the URLconf::
- urlpatterns = patterns('',
- (r'^about/', GreetingView.as_view(greeting="G'day")),
- )
+ urlpatterns = [
+ url(r'^about/', GreetingView.as_view(greeting="G'day")),
+ ]
.. note::
@@ -268,10 +268,10 @@ The easiest place to do this is in the URLconf where you deploy your view::
from .views import VoteView
- urlpatterns = patterns('',
- (r'^about/', login_required(TemplateView.as_view(template_name="secret.html"))),
- (r'^vote/', permission_required('polls.can_vote')(VoteView.as_view())),
- )
+ urlpatterns = [
+ url(r'^about/', login_required(TemplateView.as_view(template_name="secret.html"))),
+ url(r'^vote/', permission_required('polls.can_vote')(VoteView.as_view())),
+ ]
This approach applies the decorator on a per-instance basis. If you
want every instance of a view to be decorated, you need to take a
diff --git a/docs/topics/class-based-views/mixins.txt b/docs/topics/class-based-views/mixins.txt
index f0bacca6c1..00729f36f9 100644
--- a/docs/topics/class-based-views/mixins.txt
+++ b/docs/topics/class-based-views/mixins.txt
@@ -256,13 +256,13 @@ mixin.
We can hook this into our URLs easily enough::
# urls.py
- from django.conf.urls import patterns, url
+ from django.conf.urls import url
from books.views import RecordInterest
- urlpatterns = patterns('',
+ urlpatterns = [
#...
url(r'^author/(?P<pk>\d+)/interest/$', RecordInterest.as_view(), name='author-interest'),
- )
+ ]
Note the ``pk`` named group, which
:meth:`~django.views.generic.detail.SingleObjectMixin.get_object` uses