I’m trying to send a mail to users when they signup to my django webapp. After trying the below codes so that it will get the message from a template and present it in the user email in a readable format. But It keeps displaying like this;
<django.template.base.Template object at 0x033079D0>
Instead of readable format that’s in the template. I want it to display in readable text and not like the above format.
Views:
Subject='Beta Invite'
message=loader.get_template('letter.html')
from_email='test@gmail.com'
def invite_me(request):
if request.method=="POST":
form=InviteForm(request.POST)
if form.is_valid():
form.save()
#get input data and send email to the user.
msg=EmailMessage(Subject,message,from_email,Invite.objects.values_list('email_address', flat=True))
msg.send()
return HttpResponse('Thanks For Inputting Your Email, Go Check Your Email For Our Invite!')
else:
return HttpResponse('Invalid Email Address')
else:
form=InviteForm()
return render_to_response('home.html',{'InviteForm':InviteForm},context_instance=RequestContext(request))
You need to call the templates render method. Something like:
Note: if you have “context” for the template, you will need to pass it to Context().
Please see the documenation here. They have some good examples (almost exactly this problem)