How do I add my template content to my html email?

12 views
Skip to first unread message

Michael

unread,
Jan 10, 2009, 3:41:43 PM1/10/09
to Django users
Hello,
I able to send an html email using the code below:

///

def emaildiscount(request):
subject, from_email, to = 'hello', 'us...@domain.com',
'us...@domain.com'
text_content = 'This is an important message.'
html_content = '<p>This is an <strong>important</strong> message.</
p>'
msg = EmailMultiAlternatives(subject, text_content, from_email,
[to])
msg.attach_alternative(html_content, "text/html")
msg.send()

///

However, I've now created a .htm file that I want to use as the email
content. The .htm template is over 100 lines long. I don't think
pasting the code into the view is the smart thing to do. Does django
allow the html_content variable to access my .htm file?

Thanks

alex....@gmail.com

unread,
Jan 10, 2009, 4:42:14 PM1/10/09
to Django users
You can create a template and render it the same way you would in a
view, checkout the render_to_string function(it's in django.template I
believe).

Alex

On Jan 10, 2:41 pm, Michael <i...@plushrugs.com> wrote:
> Hello,
> I able to send an html email using the code below:
>
> ///
>
> def emaildiscount(request):
>     subject, from_email, to = 'hello', 'u...@domain.com',
> 'u...@domain.com'
Reply all
Reply to author
Forward
0 new messages