tunarob
tunarob

Reputation: 3038

Python - proper syntax of .format()

I need to write a .format() like this:

"{% display_cookies_accepted {} %}".format(self.client.cookies)

{} - need to be replaced by self.client.cookies

{%, %} - is a template tag in django syntax.

How to make it working?

"{{% display_cookies_accepted {} %}}".format(self.client.cookies)

also fails.

Upvotes: 0

Views: 88

Answers (1)

Inbar Rose
Inbar Rose

Reputation: 43467

Just format the content first, and then add the django tags.

"{%" + " display_cookies_accepted {} ".format(self.client.cookies) + "%}"

Or put the tags in the format as well.

"{} display_cookies_accepted {} {}".format('{%', self.client.cookies, '%}')

Upvotes: 1

Related Questions