我希望我的用户能够编写,例如image1并使用正则表达式识别并用标签替换它。 我把它全部工作 - 但是当我将数据传递给模板进行显示时,我这样做:
<div class="container"> <p> {% articleTxt %} </p> </div>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多数民众赞成我的沮丧。 我已经尝试将模板更改为:
{% autoescape off %} {{articleTXT}} {{% autoescape %}}我也试过了
{{% articleTXT|safe %}}它总是打印标签而不是渲染它们。 反正是否有渲染标签嵌入在从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. 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:
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 textThats 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!!
最满意答案
{{ articleTXT |safe }}要么
{% autoescape off %} {{ articleTXT }} {% endautoescape %}应该做的伎俩
*注意:它的{%endautoescape%}
如果那不工作尝试,
format_html(articleTXT)在你的意见。
希望这可以帮助 :)
{{ articleTXT |safe }}or
{% autoescape off %} {{ articleTXT }} {% endautoescape %}should do the trick
*Note: its {% endautoescape %}
if that isnt working try,
format_html(articleTXT)in your views.
Hope this helps :)
更多推荐
发布评论