FCGI运行脚本时失去语言环境 [英] losing locale when running fcgi script
问题描述
我在运行的Django应用程序面临着编码的问题。
我终于找到了我的Django应用程序没有设置语言环境。
I'm facing an issue with encoding in running a django app. I finally found out my django app has no locale set.
奇怪的是,我并成立了envvars中文件正确。有了这个envvars中:
The weird thing is that I did set up the envvars file correctly. With this in envvars :
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
export APACHE_PID_FILE=/var/run/apache2.pid
## The locale used by some modules like mod_dav
export LANG=C
## Uncomment the following line to use the system default locale instead:
. /etc/default/locale
export LANG
locale
当我重新启动Apache locale命令会被执行并且我得到正确fr_FR.UTF-8设置LANG和LC _ *。
When I restart apache the locale command gets executed and I get correct fr_FR.UTF-8 settings for LANG and LC_*.
现在我成立了一个小test.fcgi脚本:
Now I set up a little test.fcgi script :
#!/usr/bin/python
def myapp(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
from commands import getoutput
return ["%s"%getoutput("locale")]
from flup.server.fcgi import WSGIServer
WSGIServer(myapp).run()
当我运行它
sudo -u www-data test.fcgi
我得到正确的区域设置为好。
但每当我通过Web浏览器访问该脚本,我没有得到任何区域设置:
I get the correct locale settings as well. But whenever I access the script through a web browser, I get no locale settings :
LANG=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
为什么阿帕奇有正确的设置,但我的FCGI脚本有没有?
How come Apache has the right setting but my fcgi script hasn't?
推荐答案
我解决它在我的<$ C $加入 DefaultInitEnv郎的en_US.UTF-8
C>站点可用/默认。现在FCGI脚本告诉我,UTF-8!
I solved it by adding DefaultInitEnv LANG "en_US.UTF-8"
in my sites-available/default
. Now the fcgi script tells me UTF-8 !
这篇关于FCGI运行脚本时失去语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!