1

in my view.py:

     subject = "Thank you for your payment!"
     template = render_to_string('cart/email_template2.html', {'name': 
     request.user.first_name, 
          'transaction_id' : transaction_id, 'total':total, 'items': items})

     to = request.user.email
     res = send_mail(subject , template , settings.EMAIL_HOST_USER, [to], 
          fail_silently=True)

in my email_template2.html:

Dear {{name}},

Thank you for making your payment towards:

Your Transaction ID is {{transaction_id}}
Total Amount Paid is {{total}} AED
 

It’s been a pleasure doing business with you and below you will see the links to 
download your purchased items.

{% for i in items %}
 
    <a href="l{{ i }}"></a>
 
{% endfor %}
Best wishes,

here is the email i receive (output):

Email received from the app

"i" are the links for the items to be downloaded but they are presented as text not links. How to add a link? I tried to add tag but in the email it stays that way.

Thanks...

Rami
  • 21
  • 5

1 Answers1

0

Probably your template should have proper html structure like:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Error {{error_code}} occurred.</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
    </head>
    <body>
        <div class="container" style="margin:auto; max-width:653px; padding-top: 1rem; padding-bottom: 1rem;">
            {% block content %}
            {% endblock content %}
        </div>
    </body>
</html>

and add this template as html_message parameter to the send_mail as it is here: How to send html email with django with dynamic content in it?

and here: https://docs.djangoproject.com/en/4.0/topics/email/

akun.dev
  • 329
  • 1
  • 5
  • if i use strip_tags it will not show a link. I am tring to have a link Download i only see the word Download while using strip_tags – Rami Jan 07 '22 at 09:06