简体   繁体   中英

Django: Avoid rendering as variable in template

I just started learning django for a few day. Django's templating system looks fascinating. but currently I am facing an issue. I need to print this kind of text in my webpage multiple times through template.

She {{ was }} a very  {{ helpful }} and {{ attractive}} girl.

But whenever I try to use this in template, it thinks those words are variable thaI am referring, and vanishes them from the output due to not getting a value. So the output becomes,

She a very and girl.

I completely understand that this is the intended behaviour, but in some case I am trying to tell the rendering engine to render that as it is. Is there any filter or workaround?? [ I have to use them inside the template, and they can't be passed through variables as string]

You can use the verbatim template tag, which will stop rendering what is inside the tag. See docs here .

{% verbatim %}
    She {{ was }} a very  {{ helpful }} and {{ attractive}} girl.
{% endverbatim %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM