目前,标识符跟踪非常粗糙,并且仅基于前缀变量。 这个想法是将一些唯一的变量重写为可以反转的唯一标识符。
这应该使得不必在整个代码中使用 locals() 并修复函数边界上的标识符的一些问题。
你怎么知道你受到这个问题的影响? 你会得到一些类似于“未绑定变量 l_SOMETHING”的内容。
来自#pocoo 刚刚:
magicbronson: hey mitsuhiko et al., trying to render a Jinja template in a Flask app and getting a very mysterious message: "global name 'l_config' is not defined"
magicbronson: l_config appears nowhere in my code or libraries'
mitsuhiko: magicbronson: that's the scoping bug that i will fix over this summer
mitsuhiko: {% macro foo() %}{{ config }}{% for config in something_else %}{{config}}{% endfor %}{% endmacro %}
mitsuhiko: something like this triggers the bug currently
mitsuhiko: magicbronson: rename the variable inside of the macro to something else
mitsuhiko: {% set cfg = config %}
mitsuhiko: outside the macro
mitsuhiko: or something
Armin 的建议解决了这个问题。
这终于完成了。
最有用的评论
这终于完成了。