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",("to_example@example.com",),"from@example.com",{},context=RequestContext(request))
"""
body=loader.render_to_string(view,*args,**kwargs)
send_mail(subject,body,from_email,to_emails)
|
More like this
- IfValueTag by adurdin 4 years, 10 months ago
- Use email addresses for user name for django 1.3 by kidzik 8 months ago
- email rendered via javascript (trick spam crawlers) by rizumu 2 years, 6 months ago
- Execute a signal once by johnnoone 2 years, 9 months ago
- Newsletter email template by jibbolo 5 months ago
Comments
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."
#