[Django]-Have unicode characters in url

2👍

You need to put a u in front of r before the string, or wrap it in the unicode method:

See this for more info.

Unicode strings are much like strings, but are specified in the syntax
using a preceding ‘u’ character: u’abc’, u”def”.

http://docs.python.org/library/stdtypes.html

👤Alex W

1👍

First, to use non-ASCII characters in a string literal in Python you need to specify a character encoding at the top of your source file e.g.:

# -*- coding: utf-8 -*-

Second, if you pass a Unicode string to django it usually does the right thing by itself. In this case it should convert all non-ASCII characters in the URL. If it is not then you could call django.utils.encoding.iri_to_uri() explicitly.

👤jfs

Leave a comment