diff --git a/docs/ref/class-based-views/base.txt b/docs/ref/class-based-views/base.txt
index 5e0360c..3f82b44 100644
a
|
b
|
themselves or inherited from. They may not provide all the capabilities
|
8 | 8 | required for projects, in which case there are Mixins and Generic class-based |
9 | 9 | views. |
10 | 10 | |
| 11 | View |
| 12 | ---- |
| 13 | |
11 | 14 | .. class:: django.views.generic.base.View |
12 | 15 | |
13 | 16 | The master class-based base view. All other class-based views inherit from |
… |
… |
views.
|
31 | 34 | **Example urls.py**:: |
32 | 35 | |
33 | 36 | from django.conf.urls import patterns, url |
34 | | |
| 37 | |
35 | 38 | from myapp.views import MyView |
36 | | |
| 39 | |
37 | 40 | urlpatterns = patterns('', |
38 | 41 | url(r'^mine/$', MyView.as_view(), name='my-view'), |
39 | 42 | ) |
40 | | |
| 43 | |
41 | 44 | **Methods** |
42 | 45 | |
43 | 46 | .. method:: dispatch(request, *args, **kwargs) |
… |
… |
views.
|
61 | 64 | |
62 | 65 | The default implementation returns ``HttpResponseNotAllowed`` with list |
63 | 66 | of allowed methods in plain text. |
64 | | |
65 | | .. note:: |
| 67 | |
| 68 | .. note:: |
66 | 69 | |
67 | 70 | Documentation on class-based views is a work in progress. As yet, only the |
68 | 71 | methods defined directly on the class are documented here, not methods |
69 | 72 | defined on superclasses. |
70 | 73 | |
| 74 | TemplateView |
| 75 | ------------ |
| 76 | |
71 | 77 | .. class:: django.views.generic.base.TemplateView |
72 | 78 | |
73 | 79 | Renders a given template, passing it a ``{{ params }}`` template variable, |
… |
… |
views.
|
84 | 90 | 1. :meth:`dispatch()` |
85 | 91 | 2. :meth:`http_method_not_allowed()` |
86 | 92 | 3. :meth:`get_context_data()` |
87 | | |
| 93 | |
88 | 94 | **Example views.py**:: |
89 | 95 | |
90 | 96 | from django.views.generic.base import TemplateView |
91 | | |
| 97 | |
92 | 98 | from articles.models import Article |
93 | 99 | |
94 | 100 | class HomePageView(TemplateView): |
95 | 101 | |
96 | 102 | template_name = "home.html" |
97 | | |
| 103 | |
98 | 104 | def get_context_data(self, **kwargs): |
99 | 105 | context = super(HomePageView, self).get_context_data(**kwargs) |
100 | 106 | context['latest_articles'] = Article.objects.all()[:5] |
101 | 107 | return context |
102 | | |
| 108 | |
103 | 109 | **Example urls.py**:: |
104 | 110 | |
105 | 111 | from django.conf.urls import patterns, url |
… |
… |
views.
|
126 | 132 | * ``params``: The dictionary of keyword arguments captured from the URL |
127 | 133 | pattern that served the view. |
128 | 134 | |
129 | | .. note:: |
| 135 | .. note:: |
130 | 136 | |
131 | 137 | Documentation on class-based views is a work in progress. As yet, only the |
132 | 138 | methods defined directly on the class are documented here, not methods |
133 | 139 | defined on superclasses. |
134 | 140 | |
| 141 | RedirectView |
| 142 | ------------ |
| 143 | |
135 | 144 | .. class:: django.views.generic.base.RedirectView |
136 | 145 | |
137 | 146 | Redirects to a given URL. |
… |
… |
views.
|
159 | 168 | |
160 | 169 | from django.shortcuts import get_object_or_404 |
161 | 170 | from django.views.generic.base import RedirectView |
162 | | |
| 171 | |
163 | 172 | from articles.models import Article |
164 | 173 | |
165 | 174 | class ArticleCounterRedirectView(RedirectView): |
… |
… |
views.
|
176 | 185 | |
177 | 186 | from django.conf.urls import patterns, url |
178 | 187 | from django.views.generic.base import RedirectView |
179 | | |
| 188 | |
180 | 189 | from article.views import ArticleCounterRedirectView |
181 | 190 | |
182 | 191 | urlpatterns = patterns('', |
… |
… |
views.
|
217 | 226 | behavior they wish, as long as the method returns a redirect-ready URL |
218 | 227 | string. |
219 | 228 | |
220 | | .. note:: |
| 229 | .. note:: |
221 | 230 | |
222 | 231 | Documentation on class-based views is a work in progress. As yet, only the |
223 | 232 | methods defined directly on the class are documented here, not methods |
diff --git a/docs/ref/class-based-views/generic-date-based.txt b/docs/ref/class-based-views/generic-date-based.txt
index 69a98df..6730923 100644
a
|
b
|
Generic date views
|
5 | 5 | Date-based generic views (in the module :mod:`django.views.generic.dates`) |
6 | 6 | are views for displaying drilldown pages for date-based data. |
7 | 7 | |
| 8 | ArchiveIndexView |
| 9 | ---------------- |
| 10 | |
8 | 11 | .. class:: django.views.generic.dates.ArchiveIndexView |
9 | 12 | |
10 | 13 | A top-level index page showing the "latest" objects, by date. Objects with |
… |
… |
are views for displaying drilldown pages for date-based data.
|
21 | 24 | * :class:`django.views.generic.list.MultipleObjectMixin` |
22 | 25 | * :class:`django.views.generic.dates.DateMixin` |
23 | 26 | * :class:`django.views.generic.base.View` |
24 | | |
| 27 | |
25 | 28 | **Notes** |
26 | 29 | |
27 | 30 | * Uses a default ``context_object_name`` of ``latest``. |
28 | 31 | * Uses a default ``template_name_suffix`` of ``_archive``. |
29 | 32 | |
| 33 | YearArchiveView |
| 34 | --------------- |
| 35 | |
30 | 36 | .. class:: django.views.generic.dates.YearArchiveView |
31 | 37 | |
32 | 38 | A yearly archive page showing all available months in a given year. Objects |
… |
… |
are views for displaying drilldown pages for date-based data.
|
86 | 92 | |
87 | 93 | * Uses a default ``template_name_suffix`` of ``_archive_year``. |
88 | 94 | |
| 95 | MonthArchiveView |
| 96 | ---------------- |
| 97 | |
89 | 98 | .. class:: django.views.generic.dates.MonthArchiveView |
90 | 99 | |
91 | 100 | A monthly archive page showing all objects in a given month. Objects with a |
… |
… |
are views for displaying drilldown pages for date-based data.
|
134 | 143 | |
135 | 144 | * Uses a default ``template_name_suffix`` of ``_archive_month``. |
136 | 145 | |
| 146 | WeekArchiveView |
| 147 | --------------- |
| 148 | |
137 | 149 | .. class:: django.views.generic.dates.WeekArchiveView |
138 | 150 | |
139 | 151 | A weekly archive page showing all objects in a given week. Objects with a |
… |
… |
are views for displaying drilldown pages for date-based data.
|
175 | 187 | |
176 | 188 | * Uses a default ``template_name_suffix`` of ``_archive_week``. |
177 | 189 | |
| 190 | DayArchiveView |
| 191 | -------------- |
| 192 | |
178 | 193 | .. class:: django.views.generic.dates.DayArchiveView |
179 | 194 | |
180 | 195 | A day archive page showing all objects in a given day. Days in the future |
… |
… |
are views for displaying drilldown pages for date-based data.
|
225 | 240 | |
226 | 241 | * Uses a default ``template_name_suffix`` of ``_archive_day``. |
227 | 242 | |
| 243 | TodayArchiveView |
| 244 | ---------------- |
| 245 | |
228 | 246 | .. class:: django.views.generic.dates.TodayArchiveView |
229 | 247 | |
230 | 248 | A day archive page showing all objects for *today*. This is exactly the |
… |
… |
are views for displaying drilldown pages for date-based data.
|
246 | 264 | * :class:`django.views.generic.dates.DateMixin` |
247 | 265 | * :class:`django.views.generic.base.View` |
248 | 266 | |
| 267 | |
| 268 | DateDetailView |
| 269 | -------------- |
| 270 | |
249 | 271 | .. class:: django.views.generic.dates.DateDetailView |
250 | 272 | |
251 | 273 | A page representing an individual object. If the object has a date value in |
diff --git a/docs/ref/class-based-views/generic-display.txt b/docs/ref/class-based-views/generic-display.txt
index bbf0d4f..ef3bc17 100644
a
|
b
|
Generic display views
|
5 | 5 | The two following generic class-based views are designed to display data. On |
6 | 6 | many projects they are typically the most commonly used views. |
7 | 7 | |
| 8 | DetailView |
| 9 | ---------- |
| 10 | |
8 | 11 | .. class:: django.views.generic.detail.DetailView |
9 | 12 | |
10 | 13 | While this view is executing, ``self.object`` will contain the object that |
… |
… |
many projects they are typically the most commonly used views.
|
39 | 42 | from articles.models import Article |
40 | 43 | |
41 | 44 | class ArticleDetailView(DetailView): |
42 | | |
| 45 | |
43 | 46 | model = Article |
44 | 47 | |
45 | 48 | def get_context_data(self, **kwargs): |
… |
… |
many projects they are typically the most commonly used views.
|
55 | 58 | |
56 | 59 | urlpatterns = patterns('', |
57 | 60 | url(r'^(?P<slug>[-_\w]+)/$', ArticleDetailView.as_view(), name='article-detail'), |
58 | | ) |
| 61 | ) |
| 62 | |
| 63 | ListView |
| 64 | -------- |
59 | 65 | |
60 | 66 | .. class:: django.views.generic.list.ListView |
61 | 67 | |
diff --git a/docs/ref/class-based-views/generic-editing.txt b/docs/ref/class-based-views/generic-editing.txt
index a65a59b..2fac06e 100644
a
|
b
|
|
2 | 2 | Generic editing views |
3 | 3 | ===================== |
4 | 4 | |
5 | | The following views are described on this page and provide a foundation for |
| 5 | The following views are described on this page and provide a foundation for |
6 | 6 | editing content: |
7 | 7 | |
8 | 8 | * :class:`django.views.generic.edit.FormView` |
… |
… |
editing content:
|
13 | 13 | .. note:: |
14 | 14 | |
15 | 15 | Some of the examples on this page assume that a model titled 'Author' |
16 | | has been defined. For these cases we assume the following has been defined |
| 16 | has been defined. For these cases we assume the following has been defined |
17 | 17 | in `myapp/models.py`:: |
18 | 18 | |
19 | 19 | from django import models |
… |
… |
editing content:
|
25 | 25 | def get_absolute_url(self): |
26 | 26 | return reverse('author-detail', kwargs={'pk': self.pk}) |
27 | 27 | |
| 28 | FormView |
| 29 | -------- |
| 30 | |
28 | 31 | .. class:: django.views.generic.edit.FormView |
29 | 32 | |
30 | 33 | A view that displays a form. On error, redisplays the form with validation |
… |
… |
editing content:
|
69 | 72 | form.send_email() |
70 | 73 | return super(ContactView, self).form_valid(form) |
71 | 74 | |
| 75 | CreateView |
| 76 | ---------- |
72 | 77 | |
73 | 78 | .. class:: django.views.generic.edit.CreateView |
74 | 79 | |
… |
… |
editing content:
|
94 | 99 | .. attribute:: template_name_suffix |
95 | 100 | |
96 | 101 | The CreateView page displayed to a GET request uses a |
97 | | ``template_name_suffix`` of ``'_form.html'``. For |
| 102 | ``template_name_suffix`` of ``'_form.html'``. For |
98 | 103 | example, changing this attribute to ``'_create_form.html'`` for a view |
99 | 104 | creating objects for the the example `Author` model would cause the the |
100 | 105 | default `template_name` to be ``'myapp/author_create_form.html'``. |
… |
… |
editing content:
|
107 | 112 | class AuthorCreate(CreateView): |
108 | 113 | model = Author |
109 | 114 | |
| 115 | UpdateView |
| 116 | ---------- |
| 117 | |
110 | 118 | .. class:: django.views.generic.edit.UpdateView |
111 | 119 | |
112 | 120 | A view that displays a form for editing an existing object, redisplaying |
… |
… |
editing content:
|
133 | 141 | .. attribute:: template_name_suffix |
134 | 142 | |
135 | 143 | The UpdateView page displayed to a GET request uses a |
136 | | ``template_name_suffix`` of ``'_form.html'``. For |
| 144 | ``template_name_suffix`` of ``'_form.html'``. For |
137 | 145 | example, changing this attribute to ``'_update_form.html'`` for a view |
138 | 146 | updating objects for the the example `Author` model would cause the the |
139 | | default `template_name` to be ``'myapp/author_update_form.html'``. |
| 147 | default `template_name` to be ``'myapp/author_update_form.html'``. |
140 | 148 | |
141 | 149 | **Example views.py**:: |
142 | 150 | |
… |
… |
editing content:
|
146 | 154 | class AuthorUpdate(UpdateView): |
147 | 155 | model = Author |
148 | 156 | |
| 157 | DeleteView |
| 158 | ---------- |
| 159 | |
149 | 160 | .. class:: django.views.generic.edit.DeleteView |
150 | 161 | |
151 | 162 | A view that displays a confirmation page and deletes an existing object. |
… |
… |
editing content:
|
171 | 182 | .. attribute:: template_name_suffix |
172 | 183 | |
173 | 184 | The DeleteView page displayed to a GET request uses a |
174 | | ``template_name_suffix`` of ``'_confirm_delete.html'``. For |
| 185 | ``template_name_suffix`` of ``'_confirm_delete.html'``. For |
175 | 186 | example, changing this attribute to ``'_check_delete.html'`` for a view |
176 | 187 | deleting objects for the the example `Author` model would cause the the |
177 | | default `template_name` to be ``'myapp/author_check_delete.html'``. |
| 188 | default `template_name` to be ``'myapp/author_check_delete.html'``. |
178 | 189 | |
179 | 190 | |
180 | 191 | **Example views.py**:: |
… |
… |
editing content:
|
185 | 196 | |
186 | 197 | class AuthorDelete(DeleteView): |
187 | 198 | model = Author |
188 | | success_url = reverse_lazy('author-list') |
| 199 | success_url = reverse_lazy('author-list') |
diff --git a/docs/ref/class-based-views/index.txt b/docs/ref/class-based-views/index.txt
index f2271d2..9ed0762 100644
a
|
b
|
Class-based views API reference. For introductory material, see
|
6 | 6 | :doc:`/topics/class-based-views/index`. |
7 | 7 | |
8 | 8 | .. toctree:: |
9 | | :maxdepth: 1 |
| 9 | :maxdepth: 3 |
10 | 10 | |
11 | 11 | base |
12 | 12 | generic-display |
diff --git a/docs/ref/class-based-views/mixins-date-based.txt b/docs/ref/class-based-views/mixins-date-based.txt
index a65471e..6bf6f10 100644
a
|
b
|
Date-based mixins
|
3 | 3 | ================= |
4 | 4 | |
5 | 5 | |
| 6 | YearMixin |
| 7 | --------- |
| 8 | |
6 | 9 | .. class:: django.views.generic.dates.YearMixin |
7 | 10 | |
8 | 11 | A mixin that can be used to retrieve and provide parsing information for a |
… |
… |
Date-based mixins
|
36 | 39 | |
37 | 40 | Raises a 404 if no valid year specification can be found. |
38 | 41 | |
| 42 | MonthMixin |
| 43 | ---------- |
| 44 | |
39 | 45 | .. class:: django.views.generic.dates.MonthMixin |
40 | 46 | |
41 | 47 | A mixin that can be used to retrieve and provide parsing information for a |
… |
… |
Date-based mixins
|
82 | 88 | date provided. If ``allow_empty = False``, returns the previous month |
83 | 89 | that contained data. |
84 | 90 | |
| 91 | DayMixin |
| 92 | -------- |
| 93 | |
85 | 94 | .. class:: django.views.generic.dates.DayMixin |
86 | 95 | |
87 | 96 | A mixin that can be used to retrieve and provide parsing information for a |
… |
… |
Date-based mixins
|
127 | 136 | Returns a date object containing the previous day. If |
128 | 137 | ``allow_empty = False``, returns the previous day that contained data. |
129 | 138 | |
| 139 | WeekMixin |
| 140 | --------- |
| 141 | |
130 | 142 | .. class:: django.views.generic.dates.WeekMixin |
131 | 143 | |
132 | 144 | A mixin that can be used to retrieve and provide parsing information for a |
… |
… |
Date-based mixins
|
161 | 173 | Raises a 404 if no valid week specification can be found. |
162 | 174 | |
163 | 175 | |
| 176 | DateMixin |
| 177 | --------- |
| 178 | |
164 | 179 | .. class:: django.views.generic.dates.DateMixin |
165 | 180 | |
166 | 181 | A mixin class providing common behavior for all date-based views. |
… |
… |
Date-based mixins
|
204 | 219 | is greater than the current date/time. Returns |
205 | 220 | :attr:`DateMixin.allow_future` by default. |
206 | 221 | |
| 222 | BaseDateListView |
| 223 | ---------------- |
| 224 | |
207 | 225 | .. class:: django.views.generic.dates.BaseDateListView |
208 | 226 | |
209 | 227 | A base class that provides common behavior for all date-based views. There |
diff --git a/docs/ref/class-based-views/mixins-editing.txt b/docs/ref/class-based-views/mixins-editing.txt
index 8961088..95dd24f 100644
a
|
b
|
The following mixins are used to construct Django's editing views:
|
14 | 14 | Examples of how these are combined into editing views can be found at |
15 | 15 | the documentation on ``Generic editing views``. |
16 | 16 | |
| 17 | FormMixin |
| 18 | --------- |
| 19 | |
17 | 20 | .. class:: django.views.generic.edit.FormMixin |
18 | 21 | |
19 | 22 | A mixin class that provides facilities for creating and displaying forms. |
… |
… |
The following mixins are used to construct Django's editing views:
|
90 | 93 | :meth:`~django.views.generic.FormMixin.form_invalid`. |
91 | 94 | |
92 | 95 | |
| 96 | ModelFormMixin |
| 97 | -------------- |
| 98 | |
93 | 99 | .. class:: django.views.generic.edit.ModelFormMixin |
94 | 100 | |
95 | 101 | A form mixin that works on ModelForms, rather than a standalone form. |
… |
… |
The following mixins are used to construct Django's editing views:
|
147 | 153 | .. method:: form_invalid() |
148 | 154 | |
149 | 155 | Renders a response, providing the invalid form as context. |
150 | | |
| 156 | |
| 157 | |
| 158 | ProcessFormView |
| 159 | --------------- |
| 160 | |
151 | 161 | .. class:: django.views.generic.edit.ProcessFormView |
152 | 162 | |
153 | 163 | A mixin that provides basic HTTP GET and POST workflow. |
154 | 164 | |
155 | | .. note:: |
| 165 | .. note:: |
156 | 166 | |
157 | 167 | This is named 'ProcessFormView' and inherits directly from |
158 | 168 | :class:`django.views.generic.base.View`, but breaks if used |
diff --git a/docs/ref/class-based-views/mixins-multiple-object.txt b/docs/ref/class-based-views/mixins-multiple-object.txt
index b414355..8bc613b 100644
a
|
b
|
|
2 | 2 | Multiple object mixins |
3 | 3 | ====================== |
4 | 4 | |
| 5 | MultipleObjectMixin |
| 6 | ------------------- |
| 7 | |
5 | 8 | .. class:: django.views.generic.list.MultipleObjectMixin |
6 | 9 | |
7 | 10 | A mixin that can be used to display a list of objects. |
… |
… |
Multiple object mixins
|
148 | 151 | this context variable will be ``None``. |
149 | 152 | |
150 | 153 | |
| 154 | MultipleObjectTemplateResponseMixin |
| 155 | ----------------------------------- |
| 156 | |
151 | 157 | .. class:: django.views.generic.list.MultipleObjectTemplateResponseMixin |
152 | 158 | |
153 | 159 | A mixin class that performs template-based response rendering for views |
diff --git a/docs/ref/class-based-views/mixins-simple.txt b/docs/ref/class-based-views/mixins-simple.txt
index 33d0db3..085c8a5 100644
a
|
b
|
|
2 | 2 | Simple mixins |
3 | 3 | ============= |
4 | 4 | |
| 5 | ContextMixin |
| 6 | ------------ |
| 7 | |
5 | 8 | .. class:: django.views.generic.base.ContextMixin |
6 | 9 | |
7 | 10 | .. versionadded:: 1.5 |
… |
… |
Simple mixins
|
17 | 20 | Returns a dictionary representing the template context. The |
18 | 21 | keyword arguments provided will make up the returned context. |
19 | 22 | |
| 23 | TemplateResponseMixin |
| 24 | --------------------- |
| 25 | |
20 | 26 | .. class:: django.views.generic.base.TemplateResponseMixin |
21 | 27 | |
22 | 28 | Provides a mechanism to construct a |
diff --git a/docs/ref/class-based-views/mixins-single-object.txt b/docs/ref/class-based-views/mixins-single-object.txt
index a31608d..77f52b9 100644
a
|
b
|
|
2 | 2 | Single object mixins |
3 | 3 | ==================== |
4 | 4 | |
| 5 | SingleObjectMixin |
| 6 | ----------------- |
| 7 | |
5 | 8 | .. class:: django.views.generic.detail.SingleObjectMixin |
6 | 9 | |
7 | 10 | Provides a mechanism for looking up an object associated with the |
… |
… |
Single object mixins
|
86 | 89 | ``context_object_name`` is specified, that variable will also be |
87 | 90 | set in the context, with the same value as ``object``. |
88 | 91 | |
| 92 | SingleObjectTemplateResponseMixin |
| 93 | --------------------------------- |
| 94 | |
89 | 95 | .. class:: django.views.generic.detail.SingleObjectTemplateResponseMixin |
90 | 96 | |
91 | 97 | A mixin class that performs template-based response rendering for views |