Wie benutzt man get_context_data mit TemplateView in Django?
Ich versuche, so etwas zu tun:
class AboutView(TemplateView):
template_name = 'about.html'
def get_context_data(self, **kwargs):
context = super(AboutView, self).get_context_data(**kwargs)
context['dahl_books'] = Books.objects.filter(author="Dahl')
Wenn ich versuche, auf dahl_books in meinem template wie dieses:
{% for book in dahl_books %}
dahl_books
ist nicht in der template-Kontext, auch wenn die Bücher QuerySet zurückgegeben, die nicht null ist die Anzahl der Bücher. ....mache ich etwas falsch in meinem template oder in get_context_data
?
InformationsquelleAutor der Frage 9-bits | 2011-11-07
Du musst angemeldet sein, um einen Kommentar abzugeben.
Kann ich nicht testen, aber ich Wette, Sie brauchen
Ende
get_context_data
🙂InformationsquelleAutor der Antwort Jakub Gocławski