Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 858
sergzach Avatar asked Feb 17 '14 11:02

sergzach


1 Answers

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 ) %}
like image 140
Martijn Pieters Avatar answered Oct 03 '22 19:10

Martijn Pieters