Django 自动转义,忽略自动转义关闭和 |safe
我的 Django 过滤器没有做正确的事情。我期望在输出中看到实际的 html,但我看到的是 html 转义括号。我尝试过关闭自动转义,尝试过 |safe,并且我同时尝试过这两种功能。没有喜悦。卧槽?
<td>{% autoescape off %}{{ notif.output|safe|insert_breaks|linkify }}{% endautoescape %}</td>
我没有看到任何错误,只是真正不应该转义的自动转义文本。
I've got a Django filter that's not doing the right thing. I'm expecting to see actual html in the output, but what I see are html escaped brackets. I've tried autoescape off, and I've tried |safe, and I've tried both at the same time. No joy. Wtf?
<td>{% autoescape off %}{{ notif.output|safe|insert_breaks|linkify }}{% endautoescape %}</td>
I'm not seeing any errors, just autoescaped text that really shouldn't be escaped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案是:
在一台主机上运行多个版本的代码时,请确保 settings.py 中的 template_dir 指向正确的实例。
the answer to this is:
Make sure your template_dir in settings.py is pointing to the correct instance, when running multiple versions of your code on one host.
啊,我刚刚又看了一遍文档。答案是,在过滤之后< /em> 你的
安全
使字符串再次不安全。因此,要么将safe
放在最后,要么将其再次放在最后。Ah, I just read the docs again. The answer is that having any filters after your
safe
makes the string unsafe again. So either putsafe
at the end, or put it at the end again.