How can I implement string substitution in django's default templating engine? I'm trying to basically implement "hello %s" % "world"
with stringformat. I can't seem to get it right. My best attempt so far {{ "hello %s"|stringformat:"world" }}
gets me no output.
问问题
1400 次
1 回答
1
In stringformat:E
, the E
signifies the conversion types
which is Floating Point Exponential Format
in this case. Here, "world"
is not a valid conversion type, hence it fails.
This cannot be done, as the parameter into a templatetag method has to be a context variable
. The idea of stringformat
is to convert types, and not format strings the way you are looking to do.
于 2013-06-17T03:56:23.687 回答