sergzach
sergzach

Reputation: 6754

How to format with a UNICODE string to JINJA's variable in a template?

How to set format a string with unicode value in Jinja2 template?

{% set left='<span class="link" onclick="toggleLoginRegister(this)">{0}</span>'.format( registerHint ) %}

Raises UnicodeEncodeError if registerHint is a unicode string. Otherwise doesn't.

Upvotes: 5

Views: 6421

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121346

Use the |format() filter instead and Jinja will decode your string literal to unicode for you:

{% set left='<span class="link" onclick="toggleLoginRegister(this)">%s</span>'|format( registerHint ) %}

Upvotes: 10

Related Questions