如何在django中将数据发送到base.html? [英] How to send data to base.html in django?

查看:701
本文介绍了如何在django中将数据发送到base.html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来抽象django中的导航栏,并将其包含在base.html中;直接或通过模板包含。

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.

我想查询views.py中的数据,并使其可用于模板,以便我可以构建导航栏。

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

谢谢。

推荐答案

如果您需要添加需要提供给所有模板的信息,包括base .html你应该看看context_processor.py。这可以向上下文添加信息,以便您的页面具有aviable的数据。
我在这里找到一个博客: http ://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/

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/

这篇关于如何在django中将数据发送到base.html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆