views:

95

answers:

2
A: 

I think you're looking for this tutorial Chapter 4 of the Django book: The Django Template System.

See block tags and template inheritance.

Brian R. Bondy
+3  A: 

In your python code:

context['books'] = blah blah # Make a list of books somehow.
return render_to_response('popular_books.html', context)

In popular_books.html:

<p>Look, books:</p>
{% for book in books %}
    {% include "book.html" %}
{% endfor %}

Finally, in book.html:

<p>I am a book, my name is {{book.name}}</p>

There are more interesting ways to modularize, such as creating a custom tag, so that you could, for example:

<p>Look, books:</p>
{% for b in books %}
    {% book b %}
{% endfor %}
Ned Batchelder
This is what you want to do. You probably want some Book.objects.filter(...) to select your popular books and your recent books.
hughdbrown
This is a good way to do it. I pass lists of objects to my templates all the time. So often, in fact, that I have a template "list.html" that most of my other templates inherit from. (list.html has common elements like pagination control.)
Ellie P.
That's nice! How can I define {% book b %} template?