I’m running through the django tutorial, and built the sample polls app. I’ve got 5 polls in the system, visible through the admin interface to me. However, my rudimentary index view and template don’t seem to display them(instead, the template defaults to the else clause as if there were no polls).
My index view is as follows:
def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
return render_to_response('index.html', {'latest_poll_list': latest_poll_list})
And the template index.html:
{% if latest_poll_List %}
<ul>
{% for poll in latest_poll_list %}
<li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a></li>
{% endfor %}
</ul>
{% else %}
<p> No polls are available.</p>
{% endif %}
I can even do polls = Poll.objects.all() (with or without order_by and the truncation) in the manage.py shell, and it returns everything fine. What gives?
It could be a simple typo: latest_poll_List should be latest_poll_list with a lower case L on the list. Otherwise maybe try:
Also try:
in your template somewhere to see if it prints out the correct list of objects (i.e. the template is getting the correct list of polls)