I was having trouble with Django rendering some pages with templates that worked with most other pages. I dug into the issue, and saw a DjangoUnicodeDecodeError exception, from encoding.py, line 88.
Turns out that Django expects UTF-8 encoding by default, while the results that I was getting with the flickr api were ISO-8859-1 encoded (being that its targeted to the web), and the Django rendering engine was having a cow with that.
The fix was simple, but not one that I am really happy with. I changed the templates/__init__.py for my Django installation to call:
value = force_unicode(value,encoding='iso-8859-1')
in the _render_value_in_context() function.
Not the best way to solve the problem, so I am open to any suggestions on better ways to do this.
In my defense:
- I tried looking for somewhere in the Django settings where I would set the default encoding to ISO-8859, but could not find anything
- I was pressed for time, didnt want to go down a cleaner implementation that did not touch the base Django install
Turns out that Django expects UTF-8 encoding by default, while the results that I was getting with the flickr api were ISO-8859-1 encoded (being that its targeted to the web), and the Django rendering engine was having a cow with that.
The fix was simple, but not one that I am really happy with. I changed the templates/__init__.py for my Django installation to call:
value = force_unicode(value,encoding='iso-8859-1')
in the _render_value_in_context() function.
Not the best way to solve the problem, so I am open to any suggestions on better ways to do this.
In my defense:
- I tried looking for somewhere in the Django settings where I would set the default encoding to ISO-8859, but could not find anything
- I was pressed for time, didnt want to go down a cleaner implementation that did not touch the base Django install