Django,通过Mandrill发送电子邮件,没有设置language_code

时间:2014-09-10 18:15:10

标签: python django mandrill

我使用Mandrill API发送电子邮件。问题是电子邮件没有LANGUAGE_CODE

中使用的settings.py设置

在我的settings.py文件中,我有以下几行:

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.request",
    "events.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.tz",
)
...
LANGUAGE_CODE = 'es'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

managment/commands/sendmails.py中,一些发送电子邮件的代码是:

def generate_html(events):
    template = loader.get_template('mail_request_list.html')
    return template.render(Context({'events': events}))

def send_emails():
    mandril_client = mandrill.Mandrill(key)
    message = {
        'from_email': 'info@myapp.com',
        'from_name': 'myapp',
        'subject': u'Title',
    }

    events = get_events() #Other function
    html_request = generate_html(events)
    message['html'] = html_request
    message['to'] = [{
        'email': 'test_user@myapp.com',
        'type': 'to'
    }]
    mandril_client.messages.send(
         message=message
    )

html文件mail_request_list.html

<!DOCTYPE html>
<html lang="es">
<body>
{% for event in events %}
    Mes: {{ event.begin_at|date:'F'|lower }} 
    <br>
{% endfor %}
</body>
</html>

我可以发送电子邮件,但日期显示的是英文,而不是西班牙文,如何在我的应用中设置。

1 个答案:

答案 0 :(得分:0)

您需要在settings文件中正确设置DATE_FORMATLANGUAGE_CODE设置不对任何类型的格式负责。