Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyword arguments doesn't work #360

corpix opened this issue Aug 26, 2014 · 2 comments


Copy link

commented Aug 26, 2014

Can't get kwargs to work for format.
Documentation says that this function signature is:

format(value, *args, **kwargs)

So my template is:

{{ '%(foo)s — %(bar)s' | format(foo=1, bar=2) }}

I'm getting TypeError while trying to run it:

  File "/<erased>/.venv/local/lib/python2.7/site-packages/jinja2/", line 545, in do_format
    return soft_unicode(value) % (kwargs or args)
TypeError: format requires a mapping

And it's normal because kwargs in do_format filter doesn't get filled at all.
What am I doing wrong?


This comment has been minimized.

Copy link

commented Aug 27, 2014

It works for me. (Note, I had to change your fancy - sign for a normal one)

from jinja2 import Template

template =Template(""" {{ '%(foo)s - %(bar)s' | format(foo=1, bar=2) }}  """)
$ python 
 1 - 2 

What is the reason for using format, rather than just using the variables directly in {{ }} ?


This comment has been minimized.

Copy link

commented Aug 27, 2014

I have '%(foo)s — %(bar)s' in variable and it looks more complex in my template, thats was just example.

Found the root of a problem, there is another format call without kwargs. Thats causes this issue, sorry it's my fault.

@corpix corpix closed this Aug 27, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.