Answer the question
In order to leave comments, you need to log in
How to send information from queryset to template?
I need to return a list of books by the same author. I am using the get method to get information from the db.
views.py
class AuthorDetailView(generic.DetailView):
model = Author
template_name = 'catalog/author_detail.html'
def get(self, request, pk):
queryset = Book.objects.all().filter(author=pk).values('title', 'summary')
return render(request, self.template_name, context={'queryset':queryset})
<QuerySet [{'title': 'Programing c++', 'summary': 'about c++'}]>
Answer the question
In order to leave comments, you need to log in
{% for book in queryset %}
<p>Название: {{ book.title }}</p>
<p>Описание: {{ book.summary }}</p>
{% endfor %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question