Django包含来自var的意外结果

问题描述 投票:0回答:1

我从此代码中得到意外结果

foo.html:

{{ include "bar.html" with x="xx.html" y="y1"}}
{{ include "bar.html" with x="yy.html" y="y2"}}
{{ include "bar.html" y="y3"}}

bar.html:

{% if x %}
   y
   x
   {{include x}}
{% else %}
   pass
{% endif %}

如果我将bar.html代码放在modal-body之外,则代码可以正常工作但是如果modal-body中的代码给出了怪异的结果

y1
xx
<render xx.html>

y2
xx
<render xx.html>     <--- why this render xx and not yy

y3
xx
<render xx.html>     <--- still printing x and rendering xx.html

django:3.0.3python:3.6.9

django python-3.x jinja2 mdbootstrap
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.