如何在django的默认模板引擎中实现字符串替换?我试图用stringformat基本实现"hello %s" % "world"
。我似乎无法做到这一点。到目前为止,我最好的尝试{{ "hello %s"|stringformat:"world" }}
没有输出。
答案 0 :(得分:1)
在stringformat:E
中,E
表示conversion types
,在这种情况下为Floating Point Exponential Format
。这里,"world"
不是有效的转换类型,因此失败。
这不可能,因为templatetag方法中的参数必须是context variable
。 stringformat
的想法是convert types,而不是按照您希望的方式格式化字符串。