Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert string to html code in django template [duplicate]

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

  • abc
  • def
  • ghi

Currently it shows the string as it is.

I would really appreciate any help with this.

like image 248
user712378 Avatar asked Oct 16 '11 18:10

user712378


People also ask

How do I reuse a Django template?

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.

What does {% %} mean in Django?

{% %} 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.

What is Autoescape in Django template?

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.

What does {% include %} do?

{% 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.


1 Answers

{{ 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

like image 196
Timmy O'Mahony Avatar answered Sep 29 '22 02:09

Timmy O'Mahony