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

imported>Paulproteus
imported>Paulproteus
Line 489:
All Django wants is that HttpResponse. Or an exception.
 
BecauseMost it'sof convenient,the let'sDjango 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:
 
from polls.models import Poll
from django.http import HttpResponse
 
def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
Anonymous user