Search code examples
pythonflaskjinja2python-babelflask-babel

Syntax error when trying to render form field in Jinja


I am trying to get the placeholder on my form to be translated with Flask-Babel's _() function.

{{ render_field(form.search, placeholder="{{ _('Buscar') }}" }}

I get this error:

  File "/home/john/Scripts/Python/games/templates/index.html", line 45, in template
    {{ render_field(form.search, placeholder="{{ _('Buscar') }}" }}
TemplateSyntaxError: unexpected '}', expected ')'

How do I fix this?


Solution

  • You have missing ) in your source code

    {{ render_field(form.search, placeholder="{{ _('Buscar') }}" }}
    #                                                           ^
    {{ render_field(form.search, placeholder="{{ _('Buscar') }}") }}
    #                                                           ^
    

    simple :)