开发者

Simple question about characters in django urls

开发者 https://www.devze.com 2023-03-09 16:34 出处:网络
In django documentation they wrote that in urls it is only possible to use ASCII characters. It seems to be strange to me because of characters that are in IDN do开发者_如何学Gomains. For exapmle, if

In django documentation they wrote that in urls it is only possible to use ASCII characters. It seems to be strange to me because of characters that are in IDN do开发者_如何学Gomains. For exapmle, if I have IDN domain and I want to have not only ASCII characters in urls, it is really impossible by default to do this in easy way?


Yes, but so what. Python supports Punycode natively.

>>> 'xn--' + u'たとえば'.encode('punycode') + '.com'
'xn--r8j2b1a7a.com'


A simple workaround is to ask Django to match the URL as '.' regexp raw string, since it does not understand '\w' to mean your character set of UTF-8 etc.

So in urls.py you can write 'foo/bar/.+' instead of 'foo/bar/\w+' which is exclusive for English speakers, as it were. I'm just kidding.

Goodluck.

0

精彩评论

暂无评论...
验证码 换一张
取 消