1

プレーンHTMLの代わりにテンプレートを呼び出して、djangoコアメールでメールを送信するにはどうすればよいですか?

私の見解:

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

表示されている変数html_contentはプレーンな HTML ですが、ここでテンプレートを呼び出すにはどうすればよいでしょうか? このテンプレートは、電子メールのコンテンツになります。

4

1 に答える 1

1

テンプレート ローダーget_template関数を使用して、テンプレートを読み込むことができます。

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

my_context = {}
html_content = get_template('mytemplate.html').render(Context(my_context))
于 2015-05-10T02:11:11.193 に答える