1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

magic-removal: Fixed #1464 -- Fixed error in docs/tutorial04.txt. Thanks, ubernostrum

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2733 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-04-23 21:49:07 +00:00
parent 121c9c9692
commit 8b37669742

View File

@ -53,7 +53,7 @@ So let's create a ``vote()`` function in ``mysite/polls/views.py``::
def vote(request, poll_id): def vote(request, poll_id):
p = get_object_or_404(Poll, pk=poll_id) p = get_object_or_404(Poll, pk=poll_id)
try: try:
selected_choice = p.choice_set.filter(pk=request.POST['choice']) selected_choice = p.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist): except (KeyError, Choice.DoesNotExist):
# Redisplay the poll voting form. # Redisplay the poll voting form.
return render_to_response('polls/detail.html', { return render_to_response('polls/detail.html', {
@ -167,7 +167,7 @@ Change it like so::
from django.conf.urls.defaults import * from django.conf.urls.defaults import *
from mysite.polls.models import Poll from mysite.polls.models import Poll
info_dict = { info_dict = {
'queryset': Poll.objects.all(), 'queryset': Poll.objects.all(),
} }
@ -207,18 +207,18 @@ for the polls app, we manually specify a template name for the results view:
template. Note that we use ``dict()`` to return an altered dictionary in place. template. Note that we use ``dict()`` to return an altered dictionary in place.
In previous versions of the tutorial, the templates have been provided with a context In previous versions of the tutorial, the templates have been provided with a context
that contains the ``poll` and ``latest_poll_list`` context variables. However, that contains the ``poll` and ``latest_poll_list`` context variables. However,
the generic views provide the variables ``object`` and ``object_list`` as context. the generic views provide the variables ``object`` and ``object_list`` as context.
Therefore, you need to change your templates to match the new context variables. Therefore, you need to change your templates to match the new context variables.
Go through your templates, and modify any reference to ``latest_poll_list`` to Go through your templates, and modify any reference to ``latest_poll_list`` to
``object_list``, and change any reference to ``poll`` to ``object``. ``object_list``, and change any reference to ``poll`` to ``object``.
You can now delete the ``index()``, ``detail()`` and ``results()`` views You can now delete the ``index()``, ``detail()`` and ``results()`` views
from ``polls/views.py``. We don't need them anymore -- they have been replaced from ``polls/views.py``. We don't need them anymore -- they have been replaced
by generic views. by generic views.
The ``vote()`` view is still required. However, it must be modified to match The ``vote()`` view is still required. However, it must be modified to match
the new templates and context variables. Change the template call from ``polls/detail`` the new templates and context variables. Change the template call from ``polls/detail``
to ``polls/polls_detail``, and pass ``object`` in the context instead of ``poll``. to ``polls/polls_detail``, and pass ``object`` in the context instead of ``poll``.
Run the server, and use your new polling app based on generic views. Run the server, and use your new polling app based on generic views.