How to put braces in django templates?

前端 未结 3 925
终归单人心
终归单人心 2020-12-10 01:20

I need to produce an id surrounded by braces ( for example \"{1234}\" ). With the django template language, braces are also used to start a variable substitution, so I have

3条回答
  •  既然无缘
    2020-12-10 01:57

    The recommendation from the Jinja templating language works with the Django templating engine as well:

    http://jinja.pocoo.org/docs/dev/templates/#escaping

    The solution is this:

    {{ '{' }}{{ id }}{{ '}' }}
    

    Of course the other two answers work, but this is one is less verbose and more readable, in my opinion.

提交回复
热议问题