How to escape {{ or }} in django template?

前端 未结 10 1927
慢半拍i
慢半拍i 2020-12-01 04:17

Django treats {{ var }} as some variable in its template. How can I escape {{ var }} or {{ or }} such that django does no

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 05:03

    Edit: I don't really recommended this because it's not very clean, but it's still an option.

    I was searching for one that I could use with JQuery Templates and figured a way to do it without tags or filters. This is as short as I could get it:

    {{ "{{ any text }" }}}
    

    Is printed as:

    {{ any text }}
    

    Why it works? Any text within {{}} is displayed as is, as long as it doesn't have two closing braces }} in a row. Then there are three brackets in a row, django interprets two first ones as end of the variable leaving one additional closing brace.

提交回复
热议问题