在Django的意见: -如何将包含模板的变量传递到包含它的模板?
if request.is_ajax():
t = get_template('bar-templates.html')
html = t.render(Context({'edit': True, 'user':'some-user' }))
return HttpResponse(html)
有两个模板: 主模板(foo-templates.html)
其中包括模板(bar-templates.html)
。在上下文中edit
和user
传递给bar-templates.html
但是这个变量也用于foo-templates.html
。在Django中,我们使用{{ edit }}
来捕捉变量。由于这个变量进入bar-templates.html
。我怎样才能用这foo-templates.html
。
富-templates.html:
{% extends "base.html" %}
<div class="container">
{{ edit }} // Here I am not getting the edit value
{% if edit %} // I need this edit value. But this value is in context with `bar-templates.html`
do something
{% else %}
do something
{% endif %}
<div class="content">
{% include "bar-templates.html" %}
</div>
酒吧templaes.html
{{编辑}} //这里它给我的编辑值 这是模板,我从意见发送。
如何将included template
变量值用于包含它的模板。