django用apache+mod_wsgi部署后中文乱码的解决方法
2015-10-08 20:36
891 查看
主要是参考了django的官方文档:https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/
问题的起因是:自己通过python manage.py runserver 0.0.0.0:8082这种方式开启项目,中文不会乱码,但是楼主自己也在阿里云上部署了一个网站,通过django+apache+mod_wsgi+ubuntu这样的环境下配置的,却会出现中文乱码错误,
好几个月没有解决这个问题。
今天项目要添加上传中文文件,结果又碰到这种情况,本地服务器可以,阿里云服务器又不行,于是狠下心一定要干掉这个问题。下面无偿奉献出解决方法。
and localization) and you intend to allow users to upload files, you must 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 UnicodeEncodeErrorexceptions
when calling functions like the ones in 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:
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.
也就是需要在:
/etc/apache2/envvars中添加:
添加完后执行apache2服务重新启动命令
sudo service apache2 restart
另外顺带把django上传带有中文名字文件报错UnicodeEncodeError的问题也给你们解决了,
但是上传的文件却出现了:[Errno 13] Permission denied 的错误,那是因为你没有给部署的网站项目目录以写权限
解决方法:执行下面的命令,把search替换成你的网站项目目录即可,
sudo chmod g+w -R search/
sudo chgrp www-data -R search/
注意:不要漏掉 -R , 这是递归赋予写权限,否则仍然报错,不要漏了/
找了几个月的各种资料,文档,就解决了这两个很重要的问题,天道酬勤!
问题的起因是:自己通过python manage.py runserver 0.0.0.0:8082这种方式开启项目,中文不会乱码,但是楼主自己也在阿里云上部署了一个网站,通过django+apache+mod_wsgi+ubuntu这样的环境下配置的,却会出现中文乱码错误,
好几个月没有解决这个问题。
今天项目要添加上传中文文件,结果又碰到这种情况,本地服务器可以,阿里云服务器又不行,于是狠下心一定要干掉这个问题。下面无偿奉献出解决方法。
If you get a UnicodeEncodeError¶
If you’re taking advantage of the internationalization features of Django (see Internationalizationand localization) and you intend to allow users to upload files, you must 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 UnicodeEncodeErrorexceptions
when calling functions like the ones in 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.
也就是需要在:
/etc/apache2/envvars中添加:
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
添加完后执行apache2服务重新启动命令
sudo service apache2 restart
另外顺带把django上传带有中文名字文件报错UnicodeEncodeError的问题也给你们解决了,
但是上传的文件却出现了:[Errno 13] Permission denied 的错误,那是因为你没有给部署的网站项目目录以写权限
解决方法:执行下面的命令,把search替换成你的网站项目目录即可,
sudo chmod g+w -R search/
sudo chgrp www-data -R search/
注意:不要漏掉 -R , 这是递归赋予写权限,否则仍然报错,不要漏了/
找了几个月的各种资料,文档,就解决了这两个很重要的问题,天道酬勤!
相关文章推荐
- Linux下修改MySQL编码的方法
- cmd模式下中文乱码的解决方法(注册表)
- 解决mysql5中文乱码问题的方法
- EBS xml publisher中文乱码问题及解决办法
- ExtJS中文乱码之GBK格式编码解决方案及代码
- php url地址栏传中文乱码解决方法集合
- 常见php与mysql中文乱码问题解决办法
- 网站开发防止中文乱码需要了解的codepage的重要性小结
- php中json_encode UTF-8中文乱码的更好解决方法
- js escape,unescape解决中文乱码问题的方法
- js url传值中文乱码之解决之道
- JQuery异步获取返回值中文乱码的解决方法
- JSP中文乱码常见3个例子及其解决方法
- django中使用jquery ajax post数据出现403错误的解决办法(两种方法)
- django使用ajax post数据出现403错误如何解决
- 如何解决JQuery ajaxSubmit提交中文乱码
- jquery向.ashx文件post中文乱码问题的解决方法
- 通过过滤器(Filter)解决JSP的Post和Request中文乱码问题
- opensuse下如何解决jfreechart中文乱码的问题
- DOS命令行窗口mysql中文显示乱码问题解决方法