carl-lopez
carl-lopez

Reputation: 582

How to send data to base.html in django?

I'm looking for a way to abstract a navigation bar in django and include it in base.html; directly or through a template inclusion.

The part where I'm totally lost is, how to append data to the context so the nav bar can get its contents from database.

I'd like to query the data in views.py and make it available for the template so I can build the nav bar.

Thanks.

Upvotes: 2

Views: 3303

Answers (2)

tcarlander
tcarlander

Reputation: 102

If you need to add information that needs to be available to all templates including base.html you should look at the context_processor.py. This can add information to the context so your page have the data aviailable. I found a blog about this here: http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/

Upvotes: 5

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798764

No you wouldn't. Write a custom template tag instead.

<html>
 ...
<div class="navbar">{% navbar %}</div>
 ...
</html>

Upvotes: 7

Related Questions