November 2015
Beginner to intermediate
840 pages
26h 30m
English
get_object_or_404()Our first shortcut, get_object_or_404(), is a complete replacement for the try...except block that currently exists in our tag_detail() function.
Let’s start by importing it into our /organizer/views.py file, as in Example 5.17.
Example 5.17: Project Code
organizer/views.py in 5705e49877
2 from django.shortcuts import get_object_or_404
We can then delete the following lines, as in Example 5.18.
Example 5.18: Project Code
organizer/views.py in 294dabd8cc
18 try: 19 tag = Tag.objects.get(slug--iexact=slug) 20 except Tag.DoesNotExist: 21 raise Http404
We replace the content in Example 5.18 with the code in ...
Read now
Unlock full access