我目前正在以编程方式调用dumpdata来从我的django应用程序中导出数据。
from django.core.management import call_command
# and various other imports not directly relevant
response = HttpResponse(mimetype='application/json', )
response['Content-Disposition'] = "filename=%s" % backup_name
sys.stdout = response
call_command('dumpdata')
导出效果很好(如果有点慢),但之后settings.LANGUAGE_CODE会被忽略,所有页面都会恢复为原始语言英语。你知道为什么会发生这种情况吗?
我使用以下代码:- Python 2.7 - Django 1.3 - Rosetta用于管理语言翻译
发布于 2011-08-23 05:52:40
这可能是由django.core.management.base.BaseCommand
对象中的代码引起的。代码中的解释是:
# Switch to English, because django-admin.py creates database content
# like permissions, and those shouldn't contain any translations.
# But only do this if we can assume we have a working settings file,
# because django.utils.translation requires settings.
执行实际语言切换的代码是:
from django.utils import translation
translation.activate('en-us')
https://stackoverflow.com/questions/7149142
复制相似问题