[TimLinux] django CentOS7中django+httpd+mod_wsgi中文UnicodeEncodeError错误

1. 错误

web端访问页面,页面内的view函数要写一个含有中文名字的文件,出现了这个错误。在PyCharm开发调皮环境中不存在这样的错误,把系统部署到http, mod_wsgi时出现。

2. 定位

是文件编码问题?还是mod_wsgi的问题?还是http的问题?

3. 解决

CentOS7 使用了systemd启动httpd.service服务。为此需要查看了/etc/systemd/system/multi-user.target.wants/httpd.service文件,这个文件是链接到/usr/lib/systemd/system/httpd.service,打开文件,有一个配置项: EnvironmentFile=/etc/sysconfig/httpd,这个文件是用来配置httpd启动时的环境变量的,在该文件的底部有一个配置项: LANG=C,将该配置项改为两行内容: LANG=en_US.UTF-8,和另外一行LC_ALL=en_US.UTF-8。重启服务: systemctl restart httpd.service,问题解决。

 

posted @ 2019-02-25 10:45  TimLinux  阅读(217)  评论(0编辑  收藏  举报