Sending a html email in Django [duplicate] Sending a html email in Django [duplicate] django django

Sending a html email in Django [duplicate]


Yes, you can. In my own project, I use the following code to do the same thing:

from django.template import loaderhtml_message = loader.render_to_string(            'path/to/your/htm_file.html',            {                'user_name': user.name,                'subject':  'Thank you from' + dynymic_data,                //...              }        )send_mail(subject,message,from_email,to_list,fail_silently=True,html_message=html_message)

And the html file looks like this:

<!DOCTYPE html><html>    <head>    </head>    <body>        <h1>{{ user_name }}</h1>        <h2>{{ subject }}</h2>    </body></html>