summaryrefslogtreecommitdiff
path: root/docs/tutorial03.txt
diff options
context:
space:
mode:
Diffstat (limited to 'docs/tutorial03.txt')
-rw-r--r--docs/tutorial03.txt14
1 files changed, 7 insertions, 7 deletions
diff --git a/docs/tutorial03.txt b/docs/tutorial03.txt
index 3a830eb76f..c4c1b4c546 100644
--- a/docs/tutorial03.txt
+++ b/docs/tutorial03.txt
@@ -91,7 +91,7 @@ Finally, it calls that ``detail()`` function like so::
The ``poll_id='23'`` part comes from ``(?P<poll_id>\d+)``. Using parenthesis around a
pattern "captures" the text matched by that pattern and sends it as an argument
to the view function; the ``?P<poll_id>`` defines the name that will be used to
-identify the matched pattern; and ``\d+`` is a regular experession to match a sequence of
+identify the matched pattern; and ``\d+`` is a regular expression to match a sequence of
digits (i.e., a number).
Because the URL patterns are regular expressions, there really is no limit on
@@ -189,7 +189,7 @@ publication date::
from django.http import HttpResponse
def index(request):
- latest_poll_list = Poll.objects.all().order_by('-pub_date')
+ latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
output = ', '.join([p.question for p in latest_poll_list])
return HttpResponse(output)
@@ -202,7 +202,7 @@ So let's use Django's template system to separate the design from Python::
from django.http import HttpResponse
def index(request):
- latest_poll_list = Poll.objects.all().order_by('-pub_date')
+ latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
t = loader.get_template('polls/index.html')
c = Context({
'latest_poll_list': latest_poll_list,
@@ -257,7 +257,7 @@ provides a shortcut. Here's the full ``index()`` view, rewritten::
from mysite.polls.models import Poll
def index(request):
- latest_poll_list = Poll.objects.all().order_by('-pub_date')
+ latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list})
Note that we no longer need to import ``loader``, ``Context`` or
@@ -288,7 +288,7 @@ exception if a poll with the requested ID doesn't exist.
A shortcut: get_object_or_404()
-------------------------------
-It's a very common idiom to use ``get_object()`` and raise ``Http404`` if the
+It's a very common idiom to use ``get()`` and raise ``Http404`` if the
object doesn't exist. Django provides a shortcut. Here's the ``detail()`` view,
rewritten::
@@ -313,8 +313,8 @@ exist.
foremost design goals of Django is to maintain loose coupling.
There's also a ``get_list_or_404()`` function, which works just as
-``get_object_or_404()`` -- except using ``get_list()`` instead of
-``get_object()``. It raises ``Http404`` if the list is empty.
+``get_object_or_404()`` -- except using ``filter()`` instead of
+``get()``. It raises ``Http404`` if the list is empty.
Write a 404 (page not found) view
=================================