在 Django 管理更改列表中显示未转义的 HTML 字符串

发布于 2024-09-13 04:20:03 字数 542 浏览 0 评论 0原文

我目前面临着一个严重的问题。 我使用标准 django 管理界面,包括。更改列表以显示我的模型之一。 该模型有一个字段,其中包含一个链接(例如在数据库中:http://localhost:8000/data/somefile.pdf'>link)。

我现在想要的是这个字符串以未转义的方式呈现并显示为链接。我已经在“change_list_results.html”中尝试了以下操作:

{% for result in results %}
<tr id="{{ result.1|adminfilter }}" class="{% cycle 'row1' 'row2' %}">
    {% for item in result %}
        {{ item|safe }}
    {% endfor %}</tr>
{% endfor %}

我在输出的实际项目上使用了“|safe”。此外,我尝试了“{% autoescape off %}”。同样的结果,字符串被转义了。

您是否看到任何其他方法可以使字符串显示为未转义?

I am currently facing a serious problem.
I use the standard django admin interface incl. change list to display one of my models.
The model has got a field, which includes a link (e.g. in database: http://localhost:8000/data/somefile.pdf'>link).

What I want now is that this string is rendered unescaped and displayed as link. I already tried the following in "change_list_results.html":

{% for result in results %}
<tr id="{{ result.1|adminfilter }}" class="{% cycle 'row1' 'row2' %}">
    {% for item in result %}
        {{ item|safe }}
    {% endfor %}</tr>
{% endfor %}

I used "|safe" on the actual item that is output. Furthermore i tried "{% autoescape off %}". Same result, the String got escaped.

Do you see any other way to get the String displayed unescaped?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜`诱少女 2024-09-20 04:20:03

您想要在您的方法上设置 allow_tags=True 。它有点隐藏,但它在文档中进行了描述 - 关于屏幕左右的位置 此链接带您。

You want to set allow_tags=True on your method. It's a bit hidden, but it is described in the documentation - about a screen or so down from where this link takes you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文