Possible Duplicate:
django: rendering a template variable as html
I am developing a django site and I have a string variable which has html tags in it. I need that string to be read as html code on my template.
For instance if I have a string variable
description = "<ul><li>abc</li><li>def</li><li>ghi</li></ul>
"
When I call this string variable in my template, I would like it to be displayed as
Currently it shows the string as it is.
I would really appreciate any help with this.
To reuse a Django template you use the Django built-in {% extends %} tag. The {% extends %} tag uses the syntax {% extends <name> %} to reuse the layout of another template. This means that in order to reuse the layout in listing 3-10 defined in a file base. html , you use the syntax {% extends "base.
{% %} and {{ }} are part of Django templating language. They are used to pass the variables from views to template. {% %} is basically used when you have an expression and are called tags while {{ }} is used to simply access the variable.
autoescape. Controls the current auto-escaping behavior. This tag takes either on or off as an argument and that determines whether auto-escaping is in effect inside the block. The block is closed with an endautoescape ending tag.
{% include %} Processes a partial template. Any variables in the parent template will be available in the partial template. Variables set from the partial template using the set or assign tags will be available in the parent template.
{{ description | safe }}
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#safe
more
https://docs.djangoproject.com/en/dev/topics/templates/#automatic-html-escaping
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With