【问题标题】:Django email translation only works locallyDjango 电子邮件翻译仅在本地工作
【发布时间】:2016-08-09 19:29:54
【问题描述】:

我正在尝试根据用户在 user.language 中设置的语言向我的用户发送翻译后的电子邮件。为了做到这一点,我覆盖了 BaseMailerService 中的 send_mail 方法。

from django.utils.translation import override

    class BaseTranslatedMailerService(BaseMailerService):
        """
        Renders the acutal content of an email according to the users configurated
        language.
        """

        def send_mail(self, context, attachments=None):
            recipient_obj = context.get('recipient').get('user_obj')
            # Default for all language settings is 'en'
            with override(recipient_obj.language):
                return super(BaseTranslatedMailerService, self).send_mail(context=context,
                                                                          attachments=attachments)

在本地,在我的测试中,我让它根据 user.language 发送邮件的翻译版本,但在我的服务器环境中,它每次只发送英文邮件。也许它与我必须设置的线程语言有关?

【问题讨论】:

    标签: python django email django-rest-framework


    【解决方案1】:

    显然我不小心将所有 *.mo 文件添加到了我的 gitignore 中,导致我的编译语言字符串被排除在部署过程之外。为此从 gitignore 中删除 *.mo 解决了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多