mirror of https://github.com/django/django.git
Fixed #19335 - Typo and cleanups in docs/topics/class-based-views/index.txt
This commit is contained in:
parent
978d4476cf
commit
e2b1808196
|
@ -24,9 +24,9 @@ Basic examples
|
||||||
Django provides base view classes which will suit a wide range of applications.
|
Django provides base view classes which will suit a wide range of applications.
|
||||||
All views inherit from the :class:`~django.views.generic.base.View` class, which
|
All views inherit from the :class:`~django.views.generic.base.View` class, which
|
||||||
handles linking the view in to the URLs, HTTP method dispatching and other
|
handles linking the view in to the URLs, HTTP method dispatching and other
|
||||||
simple features. :class:`~django.views.generic.base.RedirectView` is for a simple HTTP
|
simple features. :class:`~django.views.generic.base.RedirectView` is for a
|
||||||
redirect, and :class:`~django.views.generic.base.TemplateView` extends the base class
|
simple HTTP redirect, and :class:`~django.views.generic.base.TemplateView`
|
||||||
to make it also render a template.
|
extends the base class to make it also render a template.
|
||||||
|
|
||||||
|
|
||||||
Simple usage in your URLconf
|
Simple usage in your URLconf
|
||||||
|
@ -34,7 +34,8 @@ Simple usage in your URLconf
|
||||||
|
|
||||||
The simplest way to use generic views is to create them directly in your
|
The simplest way to use generic views is to create them directly in your
|
||||||
URLconf. If you're only changing a few simple attributes on a class-based view,
|
URLconf. If you're only changing a few simple attributes on a class-based view,
|
||||||
you can simply pass them into the ``as_view`` method call itself::
|
you can simply pass them into the
|
||||||
|
:meth:`~django.views.generic.base.View.as_view` method call itself::
|
||||||
|
|
||||||
from django.conf.urls import patterns, url, include
|
from django.conf.urls import patterns, url, include
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
@ -43,9 +44,10 @@ you can simply pass them into the ``as_view`` method call itself::
|
||||||
(r'^about/', TemplateView.as_view(template_name="about.html")),
|
(r'^about/', TemplateView.as_view(template_name="about.html")),
|
||||||
)
|
)
|
||||||
|
|
||||||
Any arguments given will override the ``template_name`` on the
|
Any arguments passed to :meth:`~django.views.generic.base.View.as_view` will
|
||||||
A similar overriding pattern can be used for the ``url`` attribute on
|
override attributes set on the class. In this example, we set ``template_name``
|
||||||
:class:`~django.views.generic.base.RedirectView`.
|
on the ``TemplateView``. A similar overriding pattern can be used for the
|
||||||
|
``url`` attribute on :class:`~django.views.generic.base.RedirectView`.
|
||||||
|
|
||||||
|
|
||||||
Subclassing generic views
|
Subclassing generic views
|
||||||
|
@ -67,8 +69,8 @@ and override the template name::
|
||||||
|
|
||||||
Then we just need to add this new view into our URLconf.
|
Then we just need to add this new view into our URLconf.
|
||||||
`~django.views.generic.base.TemplateView` is a class, not a function, so we
|
`~django.views.generic.base.TemplateView` is a class, not a function, so we
|
||||||
point the URL to the ``as_view`` class method instead, which provides a
|
point the URL to the :meth:`~django.views.generic.base.View.as_view` class
|
||||||
function-like entry to class-based views::
|
method instead, which provides a function-like entry to class-based views::
|
||||||
|
|
||||||
# urls.py
|
# urls.py
|
||||||
from django.conf.urls import patterns, url, include
|
from django.conf.urls import patterns, url, include
|
||||||
|
|
Loading…
Reference in New Issue