django UnicodeEncodeError

出现 UnicodeEncodeError: 'ascii' codec can't encode characters in position 53-60: ordinal not in range(128)

一般解决是

import sys
reload(sys)   
sys.setdefaultencoding('utf-8')  



但是用nginx + uwsgi 部署django时,还是会报错。


修改 uwsgi.ini 加上env = PYTHONIOENCODING=UTF-8

[uwsgi]
socket = 127.0.0.1:9090
#chdir = /data/jazywoowu/apdmedialive_proj/trunk/monitor_web
chdir = /data/home/jazywoowu/monitor_web
pythonpath = monitor_web
module = wsgi
processes = 4


env = PYTHONIOENCODING=UTF-8

#uwsgi --ini uwsgi.ini

nginx.conf的http中加上 charset utf8;

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    #
    charset  utf-8;



阅读更多
个人分类: python
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭