0
我有以下幾點:全局變量沒有{%集%}定義
的layout.html
{% if enableEntry or enableExit %}
{% from "cp.layout.html" import entry, exit %}
{% endif %}
<!DOCTYPE html>
<html lang="en">
<body>
{% if enableEntry %}{{ entry }}{% endif %}
{% if enableExit %}{{ exit }}{% endif %}
{% block body %}{% endblock %}
</body>
</html>
cp.layout.html
{% set entry %}
...
{% if offer.text_id == "mcd" %}
Mcdonald
{% elif offer.text_id == "bk" %}
Burger King
{% endif %}
...
{% endset %}
在我看來
:
def test():
.... (offer is defined here) ...
return render_template('layout.html', offer=offer)
我收到一個錯誤UndefinedError: 'offer' is undefined
有沒有辦法將視圖中具有全局作用域的變量傳遞給{%set%}區塊?
對不起,我不夠清楚https://gist.github.com/vicngtor/2a0b1228899a179cecd013e2a7ee2a93我使用從...進口 – Sparrowcide