带有nginx和django的UnicodeEncodeError

时间:2015-06-29 13:37:35

标签: python django nginx

我已经尝试了this SO answerthis doc is inapplicable,因为我正在运行nginx,我已将charset utf-8;添加到我的nginx配置中,但我仍然遇到此错误。

汇总回溯在这里:

UnicodeEncodeError at /

'ascii' codec can't encode character u'\xe1' in position 69: ordinal not in range(128)


Request Method:     GET
Request URL:    http://django/
Django Version:     1.4.20
Exception Type:     UnicodeEncodeError
Exception Value:    

'ascii' codec can't encode character u'\xe1' in position 69: ordinal not in range(128)

Exception Location:     /opt/envs/venv/lib/python2.7/genericpath.py in getmtime, line 54
Unicode error hint

The string that could not be encoded/decoded was: choacán.jpg

1 个答案:

答案 0 :(得分:0)

我认为这个错误与nginx无关。它是关于文件创建步骤的。 保存文件时,Python使用系统区域设置。

检查您的系统区域设置:

 $ python manage.py shell
 > import os
 > print os.popen("locale").read()

如果不正确,则应设置系统区域设置。

但是这样的文件名可能会给用户带来任何麻烦。请考虑为models.FileField定义自定义文件存储并为每个文件生成随机文件名 - 这是一种很好的做法。

相关问题