Fabric,无法在Django上获取默认语言环境 [英] Fabric, can't get default locale on django

查看:107
本文介绍了Fabric,无法在Django上获取默认语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下django管理命令:

I have the following django management command:

fabrictest.py

fabrictest.py

from django.core.management.base import NoArgsCommand
import locale

class Command(NoArgsCommand):

    def handle_noargs(self, **options):
        print locale.getdefaultlocale()

我可以在本地运行什么

$ /home/user/env/bin/python manage.py fabrictest
('en_US', 'UTF-8')

但是,当我使用以下结构任务远程运行命令时

However, when I run the command remotely using the following fabric task

@task
def test():
    # run manage.py using the python bin from the virtualenv

    with cd(env.project_root):
        run("/home/user/env/bin/python manage.py fabrictest")

我得到以下输出

[server] Executing task 'test'
[server] run: /home/user/env/bin/python manage.py fabrictest
[server] out: (None, None)

为什么我会得到(None, None)而不是('en_US', 'UTF-8')?这会为其他一些管理脚本(即创建超级用户时的syncdb)产生错误.

Why do I get (None, None) instead of ('en_US', 'UTF-8')?. This generates errors for some other management scritps (namely, syncdb when creating the superuser).

推荐答案

来自文档:

根据POSIX,该程序尚未调用setlocale(LC_ALL, ")使用可移植的'C'语言环境运行.调用setlocale(LC_ALL,") 让它使用由LANG变量定义的默认语言环境.自从 我们不想干扰当前的语言环境设置 以上述方式模拟行为...

According to POSIX, a program which has not called setlocale(LC_ALL, "") runs using the portable 'C' locale. Calling setlocale(LC_ALL, "") lets it use the default locale as defined by the LANG variable. Since we don't want to interfere with the current locale setting we thus emulate the behavior in the way described above...

...如果值不能,则代码和编码可以为无" 被确定.

...code and encoding can be None in case the values cannot be determined.

如果您的程序无法使用'C'语言环境运行,请调用setlocale()和/或设置适当的环境变量,例如LANG.

If you program can't run using the 'C' locale then call setlocale() and/or set appropriate environment variables e.g., LANG.

这篇关于Fabric,无法在Django上获取默认语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆