Unicode Stuff In Django
Creating the database with encoding of utf-8
Normally, you'll only need to use
smart_unicode(). Call it as early as possible on any input data that might be either Unicode or a
bytestring, and from then on, you can treat the result as always being Unicode.
django.utils.http.urlquote_plus()are versions of Python’s standard
urllib.quote_plus()that work with non-ASCII characters. (The data is converted to UTF-8 prior to encoding.)
iri_to_uri()function will not change ASCII characters that are otherwise permitted in a URL. So, for example, the character ‘%’ is not further encoded when passed to
iri_to_uri(). This means you can pass a full URL to this function and it will not mess up the query string or anything like that.
An example might clarify things here:
urlquote(u'Paris & Orléans') u'Paris%20%26%20Orl%C3%A9ans' iri_to_uri(u'/favorites/François/%s' % urlquote(u'Paris & Orléans')) '/favorites/Fran%C3%A7ois/Paris%20%26%20Orl%C3%A9ans'
If you look carefully, you can see that the portion that was generated by
urlquote() in the second example was not double-quoted when passed to
iri_to_uri(). This is a very important and useful feature.
All strings are returned from the database as Unicode strings.
In particular, rather than giving your model a
__str__() method, we recommended you implement a
Taking care in
url = u'/person/%s/?x=0&y=0' % urlquote(self.location)
Always return Unicode strings from a template tag's render() method and from template filters. Use
force_unicode() in preference to
smart_unicode() in these places.
From: Django Docs