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

magic-removal: Updated template names to include '.html' in tutorial.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2707 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2006-04-17 07:02:18 +00:00
parent cf55b5bbaf
commit 8f41483c27
2 changed files with 9 additions and 9 deletions

View File

@ -258,7 +258,7 @@ provides a shortcut. Here's the full ``index()`` view, rewritten::
def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')
return render_to_response('polls/index', {'latest_poll_list': latest_poll_list})
return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list})
Note that we no longer need to import ``loader``, ``Context`` or
``HttpResponse``.
@ -280,7 +280,7 @@ for a given poll. Here's the view::
p = Poll.objects.get(pk=poll_id)
except Poll.DoesNotExist:
raise Http404
return render_to_response('polls/detail', {'poll': p})
return render_to_response('polls/detail.html', {'poll': p})
The new concept here: The view raises the ``django.http.Http404``
exception if a poll with the requested ID doesn't exist.
@ -296,7 +296,7 @@ rewritten::
# ...
def detail(request, poll_id):
p = get_object_or_404(Poll, pk=poll_id)
return render_to_response('polls/detail', {'poll': p})
return render_to_response('polls/detail.html', {'poll': p})
The ``get_object_or_404()`` function takes a Django model module as its first
argument and an arbitrary number of keyword arguments, which it passes to the
@ -306,8 +306,8 @@ exist.
.. admonition:: Philosophy
Why do we use a helper function ``get_object_or_404()`` instead of
automatically catching the ``*DoesNotExist`` exceptions at a higher level,
or having the model API raise ``Http404`` instead of ``*DoesNotExist``?
automatically catching the ``DoesNotExist`` exceptions at a higher level,
or having the model API raise ``Http404`` instead of ``DoesNotExist``?
Because that would couple the model layer to the view layer. One of the
foremost design goals of Django is to maintain loose coupling.

View File

@ -56,7 +56,7 @@ So let's create a ``vote()`` function in ``mysite/polls/views.py``::
selected_choice = p.choice_set.filter(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
# Redisplay the poll voting form.
return render_to_response('polls/detail', {
return render_to_response('polls/detail.html', {
'poll': p,
'error_message': "You didn't select a choice.",
})
@ -192,13 +192,13 @@ objects" and "display a detail page for a particular type of object."
``object_id`` for the generic views.
By default, the ``object_detail`` generic view uses a template called
``<app name>/<module name>_detail``. In our case, it'll use the template
``"polls/poll_detail"``. Thus, rename your ``polls/detail.html`` template to
``<app name>/<module name>_detail.html``. In our case, it'll use the template
``"polls/poll_detail.html"``. Thus, rename your ``polls/detail.html`` template to
``polls/poll_detail.html``, and change the ``render_to_response()`` line in
``vote()``.
Similarly, the ``object_list`` generic view uses a template called
``<app name>/<module name>_list``. Thus, rename ``poll/index.html`` to
``<app name>/<module name>_list.html``. Thus, rename ``poll/index.html`` to
``polls/poll_list.html``.
Because we have more than one entry in the URLconf that uses ``object_detail``