我正在使用Django,我正在尝试制作模板标签以显示数据库中的数据(sqlite3)。到目前为止,这是我的models.py
class Answer(models.Model):
subject = models.ForeignKey(Subject, help_text = u'The user who supplied this answer')
question = models.ForeignKey(Question, help_text = u"The question that this is an answer to")
runid = models.CharField(u'RunID', help_text = u"The RunID (ie. year)", max_length=32)
answer = models.TextField()
def __unicode__(self):
return "Answer(%s: %s, %s)" % (self.question.number, self.subject.surname, self.subject.givenname)
这是我的view.py
def answer_list(request):
answer_info = Answer.objects.all()
answer_data = {
"answer_detail" : answer_info
}
print answer_data
return render_to_response('quizzes.html'', answer_data, context_instance=RequestContext(request))
显示数据库中的信息我的quizzes.html模板应如何显示? 到目前为止我有这个
{% for answer_list in answer_detail %}
<h3>{{ answer_list.question }}</h3>
<p>{{ answer_list.answer }}
{{ answer_list.runid }}</p>
{% endfor %}
我认为我的for循环有些问题但不确定是什么?
答案 0 :(得分:3)
answers_detail
与您在上下文字典中传递的"answer_detail"
密钥不同。标签版本中有一个额外的。