django not ready for unicode out-of-box?
Posted by Andrey Khavryuchenko on 05 Jun 2007 at 02:37 pm | Tagged as: Blog, django if (function_exists('social_bookmark')) { social_bookmark(); } ?>
Djiggit is build on the Django unicode branch and yet it require non-obvious solutions to everyday tasks.
Imagine you’re trying to present a (cyrillic) tag in url-ready form. Usually this is solved by
{{ tagname|urlencode }}
But when the ‘tagname’ contains non-ascii symbols, urlencode barfs:
KeyError at /
u'\u0420'
Request Method: GET
Request URL: http://localhost:8088/
Exception Type: KeyError
Exception Value: u'\u0420'
Exception Location: /usr/lib/python2.4/urllib.py in quote, line 1117
Template error
My current (temporary) solution is to encode this manually, in python:
urllib.quote(tagname.encode('utf8')
But this is not DRY and makes me think there’s a better way.
Perhaps it’s time to add a custom filter and push it into django codeline.
Leave a Reply
You must be logged in to post a comment.







