12/22/2010

enabling 한글 address in http django..

When 한글 address are given to django, ascii error occurs .

Solution :


$ cat /usr/local/lib/python2.6/site-packages/sitecustomize.py
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
ref1: http://bbs.python.or.kr/viewtopic.php?p=64687&highlight=&sid=cee81191b135b182f8f28a25b37d42f7
ref2: http://blog.codeguruz.com/tag/python

Then,
$ vi /usr/lib/pymodules/python2.6/django/http/__init__.py
goto line 309 (or something..)
def _convert_to_ascii(self, *values):
"""Converts all values to ascii strings."""
for value in values:
if isinstance(value, unicode):
try:
#value = value.encode('us-ascii') ## remove this line
value = value.encode('utf-8') ## add this
except UnicodeError, e:
e.reason += ', HTTP response headers must be in US-ASCII format'
raise
else:
value = str(value)
if '\n' in value or '\r' in value:
raise BadHeaderError("Header values can't contain newlines (got %r)" % (value))
yield value

댓글 없음: