我使用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>
我可以发送电子邮件,但日期显示的是英文,而不是西班牙文,如何在我的应用中设置。