I'm trying to send a Django email in a custom template that I made for my site.
However, I can't get the Django URL link to work properly. Without the template, I can get the link to work. The username works for reference.
Does anyone know how to make this work?
Here is my views.py:
#This code is in the view that sends the email
from django.core.mail import EmailMessage
from django.core.mail import EmailMultiAlternatives
from django.template.loader import get_template
from django.template import Context
subject, from_email = 'subject', '<info@mysite.com>'
plaintext = get_template('email.txt')
htmly = get_template('email.html')
username = user.username
d = { 'username': username }
text_content = plaintext.render(d)
html_content = htmly.render(d)
msg = EmailMultiAlternatives(subject, text_content, from_email, [user.email])
msg.attach_alternative(html_content, "text/html")
msg.send()
This setup is based on this answer: Creating email templates with Django
Here is the email.html file:
<h3>Hi <strong>{{ username }}</strong>,</h6>
<p> disown kvdsvnsdov vknvisodvnsdv dsdov siod vsd. Here is a link:</p>
<a href="http://domain{% url 'home' %}">Check Now</a>
Here is the email.txt:
Hi {{ username }},
disown kvdsvnsdov vknvisodvnsdv dsdov siod vsd. Here is a link:
http://domain{% url 'home' %}