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

Closed
corpix opened this issue Aug 26, 2014 · 2 comments
Closed

Keyword arguments doesn't work #360

corpix opened this issue Aug 26, 2014 · 2 comments

Comments

@corpix
Copy link

corpix 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/filters.py", 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?

@kooky
Copy link
Contributor

kooky 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) }}  """)
print(template.render())
$ python j2.py 
 1 - 2 

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

@corpix
Copy link
Author

corpix 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 as completed Aug 27, 2014
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants