2015-05-10 33 views
1

如何调用模板而不是纯HTML来发送带有django核心电子邮件的电子邮件?在django核心电子邮件中的html_content中调用模板

我的观点:

to = articles.user.email 
      html_content = '<p>This is your email content...</p>' 
      msg = EmailMultiAlternatives('You have an email',html_content,'[email protected]',[to]) 
      msg.attach_alternative(html_content,'text/html') 
      msg.send() 

在变html_content可以看到的是纯HTML,我怎么能在这里打电话的模板?这个模板将是电子邮件的内容。

+0

可能重复(http://stackoverflow.com/questions/2809547/creating-email-模板与 - 的Django) –

回答

1

您可以使用模板加载器get_template函数加载您的模板:使用Django创建电子邮件模板]的

from django.template import Context 
from django.template.loader import get_template 

my_context = {} 
html_content = get_template('mytemplate.html').render(Context(my_context))