octavian octavian - 1 year ago 87
Python Question

Django templating language doesn't display anything

I have the following code in my


questions = list(Question.objects.all())
for question in questions:
return render_to_response('questions.html', questions)

Which prints:

How much is 2 + 2?
What's the tallest mountain on Earth?

So the
list is not empty.



These are the questions!!!

{% for question in questions %}
<li><p>{{ question.content }}</p></li>
{% endfor %}


The problem is that when I access
in the browser, the questions' content is not displayed.

Why is this happening?

Answer Source

The template doesn't know about the variable name you used when you passed the context. Try:

return render_to_response('questions.html', {'questions': questions})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download