0


How to redirect to a query string URL containing non-ascii characters in DJANGO?

When I use "return HttpResponseRedirect(u'/page/?title=' + query_string)" where the query_string contains characters like "你好", I get an error "'ascii' codec can't encode characters in position 21-26: ordinal not in range(128), HTTP response headers must be in US-ASCII format"...

垃圾帖?
更新于2010-02-05 13:59:22
348 2 10
提问于2010-02-05 04:01:46
13 3
添加评论
0


In Django, you can get native support from http.py:

from django.utils.http import urlquote, urlquote_plus

And yes, these functions will invoke urllib package to call quote and quote_plus functions.

永久链接 | 垃圾帖?
回答于2010-02-05 14:02:59
348 2 10
添加评论
0


What I need is a way to turn a chinese character into the form "&#XXXXX;" but I can't find any documentation of it... anywhere..... edit: found it.... urllib.quote_plus() turns it into %e0 , etc its not the above form, but it's good...

永久链接 | 垃圾帖?
回答于2010-02-05 05:09:21
13 3
添加评论




Made with Django.

当前版本: R-0127-20090523

cc-wiki