[英]django render html tags passed from views.py
I want my user to be able to write, for example image1 and use a regex to recognize and replace that with an tag. 我希望我的用户能够编写例如image1并使用正则表达式识别并用标签替换。 I have it all working -- but when I pass the data to template for display I do so like this:
我已经全部工作了-但是当我将数据传递到模板进行显示时,我这样做是这样的:
<div class="container">
<p>
{% articleTxt %}
</p>
</div>
ArticleTxt contains: ArticleTxt包含:
This is a test Article <img src="/media/articleImages/django-allauth.png">
and that was a picture and this is another one then some more text ----
original: This is a test Article *image1* and that was a picture and this is
another one *image2* then some more text
Thats my frustration. 那就是我的无奈。 I've tried changing the template to:
我尝试将模板更改为:
{% autoescape off %} {{articleTXT}} {{% autoescape %}}
I also tried 我也试过
{{% articleTXT|safe %}}
It always prints the tags instead of rendering them. 它总是打印标签而不是渲染标签。 Is there anyway to render tags embedded in text passed from views.py to my template!!
无论如何,有没有渲染嵌入在从views.py传递到我的模板的文本中的标签!
{{ articleTXT |safe }}
or 要么
{% autoescape off %} {{ articleTXT }} {% endautoescape %}
should do the trick 应该可以
*Note: its {% endautoescape %} *注意:其{%endautoescape%}
if that isnt working try, 如果那不起作用尝试,
format_html(articleTXT)
in your views. 在您看来。
Hope this helps :) 希望这可以帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.