Con*_*der 3 html python templates tornado
只是想知道龙卷风模板中的变量范围是什么.我在模板中有这个代码,但它失败了!
{% set dictionary = {'a' : 1, ... more letters here ... 'z' : 26} %}
{% set sum = 0 %}
{% for y in x %}
{% sum += int(dictionary[y.lower()]) #x is a string, y a char %}
{% end %}
{{ sum }}
Run Code Online (Sandbox Code Playgroud)
但我得到:
ParseError: unknown operator: 'sum'
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?
只需使用set之前sum +=
{% set dictionary = {'a' : 1, ... more letters here ... 'z' : 26} %}
{% set sum = 0 %}
{% for y in x %}
{% set sum += int(dictionary[y.lower()]) #x is a string, y a char %}
{% end %}
{{ sum }}
Run Code Online (Sandbox Code Playgroud)