开发者

show fields containing html tag in django templates like ordinary html tag

开发者 https://www.devze.com 2023-04-10 15:11 出处:网络
I have a model named news,news have a field named description,I use a RichTextArea to get the value of desc开发者_高级运维ription from user,so user can enter html tags into this field,now I show the v

I have a model named news,news have a field named description,I use a RichTextArea to get the value of desc开发者_高级运维ription from user,so user can enter html tags into this field,now I show the value of description in my template like this:

<div>
<h1>{{news.Title}}</h1>
{{news.Description}}
</div>

imagine that description field contain this text:

this is a test!

  • item1
  • item2
  • item3

template show the value of description in the same way that is saved,I mean it shows tags in the template output not a formatted HTML! what should I do?


You need the safe filter:

{{news.Description|safe}}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号