Non English characters in URL

69 views
Skip to first unread message

PythonistL

unread,
May 1, 2006, 5:30:53 AM5/1/06
to Django users
Is it possible to use non English characters in URL?To explain,

in my urls.py I use

(r'^shop/(?P<shop_name>.*?)/(?P<category_name>.*?)/','shopproject.apps.shop.views.shop.IndexByCategory'),

where
category_name
can consist non English characters.In my view i use

def IndexByCategory(request,shop_name,category_name):
...
...


I noted that in my browser address bar that category_name is not
properly coded ( if consists non-English characters) and I can not use
F5( refresh) either.
Anyone solved that problem?
Thank you for help.
L.

gabor

unread,
May 1, 2006, 6:31:37 AM5/1/06
to django...@googlegroups.com


generally such situations are solved using a SlugField.. which is a
textfield that can only contain alphanumeric characters + the minus-sign
i think. so with those there are no url problems.

now back to your problem.

generally, having non-ascii characters in the URLs is problematic.

usually if they are in utf8, there's a chance that they will be displayed.

but then it also depends on the browser, for example firefox
(intentionally) does not display them correctly...

so i would recommend you to use a SlugField, if possible.

if it's not possible, and my advice did not help, please describe to us:

- the charset you use in the URL
- which browser
- an actual example (an url that exhibits the problem)

gabor

James Bennett

unread,
May 1, 2006, 6:42:56 AM5/1/06
to django...@googlegroups.com
On 5/1/06, gabor <ga...@nekomancer.net> wrote:
> but then it also depends on the browser, for example firefox
> (intentionally) does not display them correctly...

Actually, in this case there are multiple "correct" ways to display
the characters; one is to render the Unicode glyphs, which is what
Safari does, for example, and another is to show the characters in
URL-encoded format, which is what Firefox does. There are pros and
cons to each method which are probably beyond the scope of this
discussion.


--
"May the forces of evil become confused on the way to your house."
-- George Carlin

gabor

unread,
May 1, 2006, 7:08:54 AM5/1/06
to django...@googlegroups.com
James Bennett wrote:
> On 5/1/06, gabor <ga...@nekomancer.net> wrote:
>> but then it also depends on the browser, for example firefox
>> (intentionally) does not display them correctly...
>
> Actually, in this case there are multiple "correct" ways to display
> the characters; one is to render the Unicode glyphs, which is what
> Safari does, for example, and another is to show the characters in
> URL-encoded format, which is what Firefox does. There are pros and
> cons to each method which are probably beyond the scope of this
> discussion.
>

you're absolutely correct. now reading back my response, the word
'correctly' was maybe not the best word for that situation :)

gabor

Reply all
Reply to author
Forward
0 new messages