繁体   English   中英

django渲染从views.py传递的html标签

[英]django render html tags passed from views.py

我希望我的用户能够编写例如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 |safe }}

要么

{% autoescape off %} {{ articleTXT }} {% endautoescape %}

应该可以

*注意:其{%endautoescape%}

如果那不起作用尝试,

format_html(articleTXT)

在您看来。

希望这可以帮助 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM