【发布时间】:2016-11-25 14:56:53
【问题描述】:
使用bottlepy 和simple template engine 我想知道如何将整个传递 到模板的字典传递到它的子模板。
例如在我的main.py 我有:
@bottle.route('/')
@bottle.view('main')
def index():
"""main page"""
return {"name": "main", "foo": 12, "flag": True}
我想将字典中的所有值从我的main.tpl 传递给sub.tpl
$ cat sub.tpl
<h1>Hello, {{name}}</h1>
$ cat main.tpl
% include('subtemplate', name=name, foo=foo, flag=flag)
枚举每个键(如上例所示)当然不是很可扩展也不是很灵活。
那么:有没有办法传递整个环境?
类似
$ cat main.tpl
% include('subtemplate', *env)
【问题讨论】:
-
你为什么不直接通过:
include('subtemplate', index())? -
@JossieCalderon 无限递归?
-
@LukasGraf 我不明白怎么做?请?教育?我?
-
@JossieCalderon 调用
index()将再次渲染main模板,index()将再次被调用,...除非瓶子/STE 做一些魔术来检测该循环并打破它,我看不出这不会以无限递归结束
标签: python templates template-engine bottle