I am using Django and I am trying to making a template tag to display the data from my database (sqlite3). So far this is my 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)
and here is my 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))
to display the information that is in the database how should my quizzes.html template look like? so far I have this
{% for answer_list in answer_detail %}
<h3>{{ answer_list.question }}</h3>
<p>{{ answer_list.answer }}
{{ answer_list.runid }}</p>
{% endfor %}
I believe there is something slightly wrong with my for loop but unsure of what?
render_to_responseis the template name, not the URL.