Opened 13 years ago
Closed 13 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 by , 13 years ago
comment:2 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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)
small correction I have to use {{d|safe}}