M
M
maxclax2014-12-14 15:49:57
Django
maxclax, 2014-12-14 15:49:57

Django how to send a template email?

I send emails like this:

from django.core import mail
        email = mail.EmailMessage('Hello', 'Body goes here', '[email protected]',
                                  ['[email protected]'], connection=connection)

The question is how do I insert a Template and pass data to it for replacement? I do through render () scolds for HttpResponse

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2014-12-14
@maxclax

from django.template.loader import render_to_string

print render_to_string('tpl.html', {})

take a look at the render code and see what it wraps
from django.core.mail import EmailMessage
 
def custom_send_email(to_list, subject, message, sender="Ololo <[email protected]>"):
    msg = EmailMessage(subject, message, sender, to_list)
    msg.content_subtype = "html"  # Main content is now text/html
    return msg.send()

A
Ali Aliyev, 2014-12-14
@ali_aliev

We use this thing https://pypi.python.org/pypi/django-db-mailer very conveniently

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question