DJANGO:模板在本地服务器上呈现,但不会在实时服务器上呈现

时间:2016-05-07 17:27:51

标签: django sendgrid

对于我的网站,我在发送邮件之前呈现的模板在实时服务器上呈现但是它只是向我发送空模板:

我的settings.py:

ALLOWED_HOSTS = ['localhost']

SEND_BROKEN_LINK_EMAILS = True

SERVER_EMAIL = 'my email'
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = 'my email'
DEFAULT_FROM_EMAIL = 'my email'
EMAIL_HOST_PASSWORD = 'my pass'


SENDGRID_EMAIL_PORT = 587
SENDGRID_EMAIL_USERNAME = 'sendgrid credential username'
SENDGRID_EMAIL_PASSWORD = 'sendgrid credential pass'
SENDGRID_API_KEY = 'my key'

我的sendEmail.py:

def send_contact_email(subject, template_path, dynamic_content,  from_email,from_name, destination_email, destination_name):

html = get_template(template_path)
d = Context(dynamic_content)
content = html._render(d)
print(dynamic_content)

client = sendgrid.SendGridClient(settings.SENDGRID_API_KEY)


mail = Mail(
    subject = subject,
    body="Automated mail from lokafy",
    from_email=from_name + " " + "<" + from_email + ">",
    to=[destination_email],
    html=content,
    fail_silently=False,
)
client.send(mail)

和我的模板:contact-from.html:

<p>Phone number: {{ phone }}</p> <br> <p>Message from user: {{ message }}</p>

0 个答案:

没有答案