我有很多包含 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/