Django - send email as html (django-sesame )


I don't know how to send email as html. I try every example that can i find but i don't know how to implement in my code. When it's arive in mail show all the html not only the the message. Please help me to implement send as html format in my code below. Thank you

def email(request):

    campanii = Campanie.objects.order_by('-pub_date')

    if request.method == 'POST':
        form = EmailLoginForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email'].lower()
            user = UserVot.objects.filter(email=email).first()

            if user is None: # daca userul nu exista cu acea adresa de email
                messages.error(request, "adresa de email nu este corecta sau valida")
                return render(request, 'loginvot/email.html', {'form' : form, 'campanii':campanii , 'error_message' : "adresa de email nu este corecta sau valida"} )

            link += sesame.utils.get_query_string(user)

                subject="Link vot",
                            <html >
                                    <meta charset="UTF-8">

                                    <p> Salutare,  <h4>{{user.username}}</h4></p><br>
                                    <p>Acceseaza link-ul de mai jos pentru a intra in sectiunea de vot "Ambasadorii Valorilor Profi"</p><br>
            return render(request, 'loginvot/email.html', {'campanii':campanii , 'error_succes' : "in maximum 1 minut vei primi pe adresa de email completata un link de accesare sesiune de vot"} )


    context = {'form' : EmailLoginForm, 'campanii' : campanii}
    return render(request, 'loginvot/email.html', context)

The solution turned out to be much simpler than I anticipated. I put the email message in a separate file (template_mail.html) and i use funtion render_to_string then in user.email_user I added html_message wich take that template_mail. This is how the code now looks and works.

template_mail = render_to_string ('loginvot/template_email.html', {'user' : user, 'link' : link } )

                subject='Link vot Ambasadorii valorilor Profi',
                message=f"""some message""",
                html_message = template_mail

Back to Top