mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Merge pull request #1271 from batisteo/ticket-20565
Fixed #20565 -- Added template examples for GCBV.
This commit is contained in:
commit
f656757888
@ -63,7 +63,7 @@ ArchiveIndexView
|
||||
month or day using the attribute ``date_list_period``. This also applies
|
||||
to all subclass views.
|
||||
|
||||
**Example views.py**::
|
||||
**Example myapp/views.py**::
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
from django.views.generic.dates import ArchiveIndexView
|
||||
@ -160,7 +160,7 @@ YearArchiveView
|
||||
|
||||
* Uses a default ``template_name_suffix`` of ``_archive_year``.
|
||||
|
||||
**Example views.py**::
|
||||
**Example myapp/views.py**::
|
||||
|
||||
from django.views.generic.dates import YearArchiveView
|
||||
|
||||
@ -172,7 +172,7 @@ YearArchiveView
|
||||
make_object_list = True
|
||||
allow_future = True
|
||||
|
||||
**Example urls.py**::
|
||||
**Example myapp/urls.py**::
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
@ -255,7 +255,7 @@ MonthArchiveView
|
||||
|
||||
* Uses a default ``template_name_suffix`` of ``_archive_month``.
|
||||
|
||||
**Example views.py**::
|
||||
**Example myapp/views.py**::
|
||||
|
||||
from django.views.generic.dates import MonthArchiveView
|
||||
|
||||
@ -267,7 +267,7 @@ MonthArchiveView
|
||||
make_object_list = True
|
||||
allow_future = True
|
||||
|
||||
**Example urls.py**::
|
||||
**Example myapp/urls.py**::
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
@ -348,7 +348,7 @@ WeekArchiveView
|
||||
|
||||
* Uses a default ``template_name_suffix`` of ``_archive_week``.
|
||||
|
||||
**Example views.py**::
|
||||
**Example myapp/views.py**::
|
||||
|
||||
from django.views.generic.dates import WeekArchiveView
|
||||
|
||||
@ -361,7 +361,7 @@ WeekArchiveView
|
||||
week_format = "%W"
|
||||
allow_future = True
|
||||
|
||||
**Example urls.py**::
|
||||
**Example myapp/urls.py**::
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
@ -463,7 +463,7 @@ DayArchiveView
|
||||
|
||||
* Uses a default ``template_name_suffix`` of ``_archive_day``.
|
||||
|
||||
**Example views.py**::
|
||||
**Example myapp/views.py**::
|
||||
|
||||
from django.views.generic.dates import DayArchiveView
|
||||
|
||||
@ -475,7 +475,7 @@ DayArchiveView
|
||||
make_object_list = True
|
||||
allow_future = True
|
||||
|
||||
**Example urls.py**::
|
||||
**Example myapp/urls.py**::
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
@ -537,7 +537,7 @@ TodayArchiveView
|
||||
|
||||
* Uses a default ``template_name_suffix`` of ``_archive_today``.
|
||||
|
||||
**Example views.py**::
|
||||
**Example myapp/views.py**::
|
||||
|
||||
from django.views.generic.dates import TodayArchiveView
|
||||
|
||||
@ -549,7 +549,7 @@ TodayArchiveView
|
||||
make_object_list = True
|
||||
allow_future = True
|
||||
|
||||
**Example urls.py**::
|
||||
**Example myapp/urls.py**::
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
@ -599,7 +599,7 @@ DateDetailView
|
||||
|
||||
* Uses a default ``template_name_suffix`` of ``_detail``.
|
||||
|
||||
**Example urls.py**::
|
||||
**Example myapp/urls.py**::
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
from django.views.generic.dates import DateDetailView
|
||||
|
@ -36,7 +36,7 @@ DetailView
|
||||
9. ``get()``
|
||||
10. :meth:`~django.views.generic.base.TemplateResponseMixin.render_to_response()`
|
||||
|
||||
**Example views.py**::
|
||||
**Example myapp/views.py**::
|
||||
|
||||
from django.views.generic.detail import DetailView
|
||||
from django.utils import timezone
|
||||
@ -52,7 +52,7 @@ DetailView
|
||||
context['now'] = timezone.now()
|
||||
return context
|
||||
|
||||
**Example urls.py**::
|
||||
**Example myapp/urls.py**::
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
@ -62,6 +62,16 @@ DetailView
|
||||
url(r'^(?P<slug>[-_\w]+)/$', ArticleDetailView.as_view(), name='article-detail'),
|
||||
)
|
||||
|
||||
**Example myapp/article_detail.html**:
|
||||
|
||||
.. code-block:: html+django
|
||||
|
||||
<h1>{{ object.headline }}</h1>
|
||||
<p>{{ object.content }}</p>
|
||||
<p>Reporter: {{ object.reporter }}</p>
|
||||
<p>Published: {{ object.pub_date|date }}</p>
|
||||
<p>Date: {{ object.now|date }}</p>
|
||||
|
||||
ListView
|
||||
--------
|
||||
|
||||
@ -111,7 +121,7 @@ ListView
|
||||
context['now'] = timezone.now()
|
||||
return context
|
||||
|
||||
**Example urls.py**::
|
||||
**Example myapp/urls.py**::
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
@ -121,6 +131,19 @@ ListView
|
||||
url(r'^$', ArticleListView.as_view(), name='article-list'),
|
||||
)
|
||||
|
||||
**Example myapp/article_list.html**:
|
||||
|
||||
.. code-block:: html+django
|
||||
|
||||
<h1>Articles</h1>
|
||||
<ul>
|
||||
{% for article in object_list %}
|
||||
<li>{{ article.pub_date|date }} - {{ article.headline }}</li>
|
||||
{% empty %}
|
||||
<li>No articles yet.</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
.. class:: django.views.generic.list.BaseListView
|
||||
|
||||
A base view for displaying a list of objects. It is not intended to be used
|
||||
|
@ -42,7 +42,7 @@ FormView
|
||||
* :class:`django.views.generic.edit.ProcessFormView`
|
||||
* :class:`django.views.generic.base.View`
|
||||
|
||||
**Example forms.py**::
|
||||
**Example myapp/forms.py**::
|
||||
|
||||
from django import forms
|
||||
|
||||
@ -54,7 +54,7 @@ FormView
|
||||
# send email using the self.cleaned_data dictionary
|
||||
pass
|
||||
|
||||
**Example views.py**::
|
||||
**Example myapp/views.py**::
|
||||
|
||||
from myapp.forms import ContactForm
|
||||
from django.views.generic.edit import FormView
|
||||
@ -70,6 +70,16 @@ FormView
|
||||
form.send_email()
|
||||
return super(ContactView, self).form_valid(form)
|
||||
|
||||
**Example myapp/contact.html**:
|
||||
|
||||
.. code-block:: html+django
|
||||
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Send message" />
|
||||
</form>
|
||||
|
||||
|
||||
CreateView
|
||||
----------
|
||||
|
||||
@ -101,7 +111,7 @@ CreateView
|
||||
creating objects for the example ``Author`` model would cause the
|
||||
default ``template_name`` to be ``'myapp/author_create_form.html'``.
|
||||
|
||||
**Example views.py**::
|
||||
**Example myapp/views.py**::
|
||||
|
||||
from django.views.generic.edit import CreateView
|
||||
from myapp.models import Author
|
||||
@ -110,6 +120,15 @@ CreateView
|
||||
model = Author
|
||||
fields = ['name']
|
||||
|
||||
**Example myapp/author_form.html**:
|
||||
|
||||
.. code-block:: html+django
|
||||
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Create" />
|
||||
</form>
|
||||
|
||||
UpdateView
|
||||
----------
|
||||
|
||||
@ -143,7 +162,7 @@ UpdateView
|
||||
updating objects for the example ``Author`` model would cause the
|
||||
default ``template_name`` to be ``'myapp/author_update_form.html'``.
|
||||
|
||||
**Example views.py**::
|
||||
**Example myapp/views.py**::
|
||||
|
||||
from django.views.generic.edit import UpdateView
|
||||
from myapp.models import Author
|
||||
@ -151,6 +170,16 @@ UpdateView
|
||||
class AuthorUpdate(UpdateView):
|
||||
model = Author
|
||||
fields = ['name']
|
||||
template_name_suffix = '_update_form'
|
||||
|
||||
**Example myapp/author_update_form.html**:
|
||||
|
||||
.. code-block:: html+django
|
||||
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Update" />
|
||||
</form>
|
||||
|
||||
DeleteView
|
||||
----------
|
||||
@ -184,8 +213,7 @@ DeleteView
|
||||
deleting objects for the example ``Author`` model would cause the
|
||||
default ``template_name`` to be ``'myapp/author_check_delete.html'``.
|
||||
|
||||
|
||||
**Example views.py**::
|
||||
**Example myapp/views.py**::
|
||||
|
||||
from django.views.generic.edit import DeleteView
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
@ -194,3 +222,12 @@ DeleteView
|
||||
class AuthorDelete(DeleteView):
|
||||
model = Author
|
||||
success_url = reverse_lazy('author-list')
|
||||
|
||||
**Example myapp/author_confirm_delete.html**:
|
||||
|
||||
.. code-block:: html+django
|
||||
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
<p>Are you sure you want to delete "{{ object }}"?</p>
|
||||
<input type="submit" value="Confirm" />
|
||||
</form>
|
||||
|
Loading…
Reference in New Issue
Block a user