Handling an undefined template variable in Tornado

后端 未结 4 933
Happy的楠姐
Happy的楠姐 2021-02-05 13:59

This is a tornado template (say, in the file logout.html) I render on an error in the logout process:

  {% if logout_error %}
    Oops! The logout failed. Please         


        
4条回答
  •  自闭症患者
    2021-02-05 14:33

    The "Tornado way" is to not have undeclared variables. It's more zen to declare the variables explicit.

    Workaround:

    {% if 'grok' in globals() %}
      {{grok}}
    {% end %}
    
    {% if globals().get('grok_error', False) %}
      error message
    {% end %}
    

提交回复
热议问题