octavian octavian - 1 month ago 17
Python Question

Django templating language doesn't display anything

I have the following code in my

views.py
:

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


Which prints:

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


So the
questions
list is not empty.

questions.html
is:

<head></head>

<body>
These are the questions!!!

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

</body>


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

Why is this happening?

Answer

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})