以编程方式调用 call_command('dumpdata') 后忽略语言设置

发布于 2024-11-30 19:47:55 字数 484 浏览 0 评论 0原文

我目前正在以编程方式调用 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 - 姜戈 1.3 - Rosetta 用于管理语言翻译

I'm currently programmatically calling dumpdata to export the data from my django app.

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')

The export works well (if a tad slow) but afterwards settings.LANGUAGE_CODE is ignored and all pages revert to back to the original language English. Any ideas why this is happening?

I'm using the following:
- Python 2.7
- Django 1.3
- Rosetta for managing language translations

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戈亓 2024-12-07 19:47:55

这可能是由 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')

This is likely caused by code in the django.core.management.base.BaseCommand object. The explanation in the code is:

# 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.

The code which does the actual language switch is:

from django.utils import translation
translation.activate('en-us')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文