0
我开始学习Django(1.11),我按照Django Tutorials。在这部分我应该创建动态视图(索引方法)与模板。但是,我创建的模板Django教程第3部分:创建视图和模板时出错
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
和索引视图后,使用模板
from django.http import HttpResponse
from django.template import loader
from .models import Question
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
template = loader.get_template('polls/index.html')
context = {
'latest_question_list': latest_question_list,
}
return HttpResponse(template.render(context, request))
我已经去了一个错误: * NameError在/调查/ *全局名称 'latest_question_list' 没有定义* *