python - Django模板问题: how to output just the text if the variable has html in it?

标签 python django

我有很多包含 html 的变量。例如,名为 {{object.name}} 的变量的值如下:

Play this <a href="#">hot</a> game and see how <b>fun</b> it is!

是否有一个可以应用于变量的过滤器,它只会给我文本:

Play this hot game and see how fun it is!

没有链接的文本或被 htmlentities 替换的 html。只是文字?

最佳答案

striptags过滤器删除所有 html

{{object.name|striptags}}

关于python - Django模板问题: how to output just the text if the variable has html in it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6359773/

相关文章:

python - 从网络开发转向桌面开发

django - 无法通过生产中的邮件拦截404错误(debug = False)

python - Djangocms 中的自定义 View ?

python - 解析日志文件时使用spark在方括号之间包含文本

django - 如何注意到在redis中已经创建了一个键

python - 明确限制 Django QuerySet

python - 如何防止从 Django Admin 中删除 Django 模型,除非是级联的一部分

python - 验证用户帐户在 Django Rest Framework 中是否处于事件状态

python - `.create()` 方法默认不支持可写嵌套字段。

python - 参数化 django 的迁移以跳过(--fake 以编程方式)