比如父模板之中存在全站的导航,每个页面需要这些导航,
而这个父模板中的导航内容是从数据库中读取的,
也就是说每次渲染继承它的模板都要传一个 list 的参数(导航列表),
感觉走了弯路呀,请问有其他方法来实现吗?
1
delo 2015 年 8 月 17 日
|
2
guoqiao 2015 年 8 月 17 日
楼上正解
|
3
virusdefender 2015 年 8 月 17 日
我是自己写了一个 template tag 实现的
|
5
le0rn0 OP @virusdefender 能否详细说下?谢啦
|
6
virusdefender 2015 年 8 月 17 日
@le0rn0 你不就是需要一个类似全局变量的东西么~
# coding=utf-8 from django import template register = template.Library () @register.simple_tag def show_website_info (name ): return {"website_name": "xxx", "website_footer": u"xxx"}[name] 然后在模板里面 {% show_website_info "website_name" %} {% show_website_info "website_footer" %} https://docs.djangoproject.com/en/1.8/howto/custom-template-tags/ |
7
glasslion 2015 年 8 月 17 日
context processor 正解
|
8
le0rn0 OP |