I've moved my django application from one server to another, and spotted strange bug with media after it:
Traceback (most recent call last):
File "/usr/lib/python2.5/site-
packages/Django-1.1.1-py2.5.egg/django/core/handlers/base.py", line 92, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.5/site-packages/Django-1.1.1-py2.5.egg/django/views/static.py", line 51, in serve
if os.path.isdir(fullpath):
File "/usr/lib/python2.5/posixpath.py", line 195, in isdir
st = os.stat(path)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 44-46: ordinal not in range(128)
The image I am try开发者_StackOverflow社区ing to access actually have Cyrillic symbols in the name, but it didn't made a problem on previous environment
Thanks, Oleg
First of all, don't have Django serve your static files. See this: http://docs.djangoproject.com/en/dev/howto/static-files/
In Django documentation it's written that this may be connected to Apache settings (discovered via here).
https://docs.djangoproject.com/en/1.4/howto/deployment/modpython/#if-you-get-a-unicodeencodeerror
"Ensure that the environment used to start Apache is configured to accept non-ASCII file names. If your environment is not correctly configured, you will trigger UnicodeEncodeError exceptions when calling functions like os.path() on filenames that contain non-ASCII characters.
To avoid these problems, the environment used to start Apache should contain settings analogous to the following:
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
Consult the documentation for your operating system for the appropriate syntax and location to put these configuration items; /etc/apache2/envvars is a common location on Unix platforms. Once you have added these statements to your environment, restart Apache."
P.S. My current hosting technical support is very slow, neither have I access to Apache settings. That's why currently I have to resort to django static serve. My site isn't too frequently visited and I've no other choice even though I know it's not optimal.
精彩评论