开发者

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 contex开发者_运维技巧t 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.


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

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


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜