Login

Render to email

Author:
bl4th3rsk1t3
Posted:
May 3, 2009
Language:
Python
Version:
1.0
Score:
0 (after 4 ratings)

Renders a view to an email. You need to set all of the required settings for email support.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from django.template import loader
from django.core.mail import send_mail
def render_to_email(view,subject,to_emails,from_email,*args,**kwargs):
	"""
	Renders a view to an email
	Example:
	render_to_email("myview.html","the subject",("[email protected]",),"[email protected]",{},context=RequestContext(request))
	"""
	body=loader.render_to_string(view,*args,**kwargs)
	send_mail(subject,body,from_email,to_emails)

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 9 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 9 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 4 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 4 months ago
  5. Help text hyperlinks by sa2812 1 year, 5 months ago

Comments

jammycakes (on May 25, 2009):

Just to clarify -- shouldn't the description say "Renders a template to an e-mail"? In Django parlance, "views" refers to what most other MVC frameworks call "controllers" and what we normally call "views" are referred to as "templates."

#

Please login first before commenting.