开发者

Django Contact Form send html emails

Is there a way to use the django-contact-form to s开发者_如何学Cend a html email?


I just looked up the source and it's not built in.

You can certainly modify it however you please -- it's a very simple form and very readable.

You'd need to add a html_template variable/path and modify the save line, and add a way to specify which template to use.

def save(self, fail_silently=False):
    """
    Build and send the email message.

    """
    data = self.get_message_dict()
    msg = EmailMultiAlternatives(subject=data['subject'], body=data['message'], from_email=data['from_email'], to=data['recipient_list'])

    msg.attach_alternative(loader.render_to_string('path_to_my_html_template.html', self.get_context()), "text/html")
    msg.send(fail_silently=fail_silently)

This is just easier to keep all of your changes in one spot.

Otherwise, you could re-write most of the code and change the method names and the strings in get_message_dict() to reflect the new field names for EmailMessage

Frankly, i'm not sure why send_mail should have different keywords than EmailMessage

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜