【发布时间】:2017-07-11 22:30:41
【问题描述】:
我希望我的用户能够编写,例如 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传递到我的模板的文本中的标签!
【问题讨论】:
-
我不明白
articleTXT中的内容是什么?它的img或text