2016-12-15 92 views

回答

-1

瓶具有app_context_processor做出模板可用变量:

context处理器运行模板呈现前必须注入新的值到模板方面的能力。

class Letters(): 
    A = 1 
    B = 2 

@app.context_processor 
def share_context(): 
    return dict(Letters=Letters) 

Now you can access this class 

# index.html 
{{ Letters.A }} 
{% if Letters.B != 1 %} 
... 
{% endif %} 

flask context processors