Skip to content

Instantly share code, notes, and snippets.

@laat
Created July 30, 2013 19:33
Show Gist options
  • Save laat/6116124 to your computer and use it in GitHub Desktop.
Save laat/6116124 to your computer and use it in GitHub Desktop.
Enkel rendring av *text* templates med django. dvs, ikke html.
#encoding=utf-8
from django.core.mail import send_mail as djsend_mail
from django.template.loader import get_template
from django.template import Context
#>>> util.send_mail('events/index.html', "lol", "fra", "til", {'events': "dette er events"})
def send_mail(template, subject, fra , to, context):
if(isinstance(to, str)): # to can be both a list of strings or a string.
to = [to]
body = get_template(template).render(Context(context))
djsend_mail(subject, body, fra, to)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment