Opened 5 years ago

Closed 5 years ago

#16571 closed Bug (invalid)

Incorrect unicode template output

Reported by: pma_ Owned by: nobody
Component: Template system Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have simple dictionary in py and I tried to output one using {{ }} to template.
Problem is that I got unecessary u in front of every unicode string and that is not acceptable by js.

d = {'id': 3, 'value': 'dolnośląskie'}

after {{d}} i have

{'id': 3, 'value': u'dolno\u015bl\u0105skie'}

Change History (2)

comment:1 Changed 5 years ago by pma_

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

small correction I have to use {{d|safe}}

comment:2 Changed 5 years ago by Aymeric Augustin

Resolution: invalid
Status: newclosed

This isn't a bug in Django; it's just the fact that Python and Javascript are different languages.

You're printing a Python dictionary in your template. But what you actually want is a Javascript dictionary.

Just convert the dictionary to JSON before passing it to your template: d = json.dumps(d)

Note: See TracTickets for help on using tickets.
Back to Top