Boston Python Workshop/Saturday/Web app project: Difference between revisions

Content added Content deleted
Line 604: Line 604:
=== Raising 404 ===
=== Raising 404 ===


Now, let's tackle the poll detail view -- the page that displays the question for a given poll. Continue editing the "views.py" file. This view uses Python ''exceptions'':
Now, let's tackle the poll detail view -- the page that displays the question for a given poll. Continue editing the ''views.py''. file. This view uses Python ''exceptions'':


from django.http import Http404
from django.http import Http404
Line 617: Line 617:
The new concept here: The view raises the Http404 exception if a poll with the requested ID doesn't exist.
The new concept here: The view raises the Http404 exception if a poll with the requested ID doesn't exist.


If you'd like to quickly get the above example working, just create a new template file and name it ''detail.html":
If you'd like to quickly get the above example working, just create a new template file and name it ''detail.html''. Enter in it just one line of code:


<pre>
<pre>
Line 623: Line 623:
</pre>
</pre>


will get you started for now.
to get you started for now.

Add it to a new template file that you create, ''detail.html''.


Does your detail view work? Try it: http://127.0.0.1:8000/polls/1/
Does your detail view work? Try it: http://127.0.0.1:8000/polls/1/