I am looking for the following feature in django
I am writing a website, it contains many pages ex: home(displays all the books), details(selected book details), search(display the books based on search).
now the home page contains blocks like featured books, just-in books, most famous books.
details pages display selected book details and it should display featured books, most famous books.
Now my Question is featured and famous books blocks are getting repeated, so is there any way to keep the template code separately(html) and also respective view method separately. so if I call these mini templates from main templates with arguments.
So that I can keep more generalized way and without repeating the code also in future if I want to change something I can do it at one place.
I am thinking to do it with filter but is that a good way? or django provided any mechanism?
You can isolate reusable blocks of HTML into templates, and then include them in other templates with the
{% include %}tag.They don’t take arguments, but you can either set up the main template so that the variables are set correctly, or use a
{% with %}tag to set the context before the{% include %}As a concrete example, your view code could set up lists of books like this:
Then, in your template (book_template.html):