33

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.

Community
  • 1
  • 1
user712378
  • 373
  • 1
  • 3
  • 8

1 Answers1

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

Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
  • 1
    It works perfectly. I want to add a class like
  • to style some elements dynamically. My CSS class is ignored, How can I do it?
  • – antonio Apr 27 '20 at 00:44