Handling an undefined template variable in Tornado

后端 未结 4 877
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:28

    Hacking around using locals().get() is one way to do it. Another, bit more orthodox is using try. Tornado template supports it, so you can:

    {% try %}
      {% if logout_error %}
        Oops! The logout failed. Please close all open documents and try again
      {% end %}
    {% except %}
    {% end %}
    

提交回复
热议问题