Search code examples
djangotemplatesdjango-querysetinherited

Queryset in an inherited Django Template


I'm new to Django and Web programming in general. Have googled but could not find the answer I need. Here's the case:

I have a site, where every page in which the user is logged has certain navigation Menu. That's why they extend a template called base_logged.html, which is also extending base.html. The problem is that the navigation menu is partly populated by a database Query.

Is there a way of populating this without making tha query in every logged view ? Or some kinda View inheritance?

Sorry for my poor english.


Solution

  • Another option is to create a custom template tag (probably an inclusion tag) and put it in your base template.

    So in your base template you could have something like this:

    {% navigation_bar user %}