问题描述
我有以下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).
推荐答案
来自文档:
...如果值不能,则代码和编码可以为无" 被确定.
...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上获取默认语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!