【问题标题】:Django template excape literal stringDjango 模板 excape 字符串
【发布时间】:2014-12-17 05:31:03
【问题描述】:

基本上是这样的

{{ ">>"|escape }} 

可能吗?

我可以使用{{ context_variable|escape}},但我可以使用字符串文字吗?

我想避免在我的模板文件中乱扔>

【问题讨论】:

标签: django-templates escaping html-escape-characters django-template-filters


【解决方案1】:

是的。 Django 将无效变量视为空字符串。当您传递字符串文字时就是这种情况。我会将字符串文字连接到一个空字符串。

这里也有这个答案。 Literal HTML in Django without using a variable?

【讨论】:

    猜你喜欢
    • 2012-06-06
    • 2017-07-17
    • 2015-03-02
    • 1970-01-01
    • 2020-11-11
    • 2016-06-09
    • 2016-01-29
    • 2012-01-11
    • 1970-01-01
    相关资源
    最近更新 更多