Steven Wexler
Steven Wexler

Reputation: 17329

String substitution in django templates

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.

Upvotes: 1

Views: 1849

Answers (1)

karthikr
karthikr

Reputation: 99680

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.

Upvotes: 1

Related Questions