Anonymous user
Boston Python Workshop/Saturday/Web app project: Difference between revisions
Boston Python Workshop/Saturday/Web app project (view source)
Revision as of 22:18, 5 March 2011
, 13 years ago→Write views that actually do something
Line 541:
All Django wants is that HttpResponse. Or an exception.
Most of the Django views in the world use Django's own database API, which we covered in Tutorial 1. Let's do that, too. Here's one stab at the index() view, which displays the latest 5 poll questions in the system, separated by commas, according to publication date. Continue editing the file views.py:
from polls.models import Poll
Line 551:
return HttpResponse(output)
There's a problem here, though: The page's design is hard-coded in the view. If you want to change the way the page looks, you'll have to edit this Python code. So let's use Django's template system to separate the design from Python
from django.shortcuts import render_to_response
|