I want to send a mail to every user that fill a form on my django website. After writing a code for it, I’m getting the below error. I’ve been trying to find the cause of the error but no success. Below are my codes:
AttributeError at /meek/
'NoneType' object has no attribute 'e_mail'
Views
Subject='Welcome'
message=loader.get_template('letter.txt')
from_email='men@men.com'
def gent_me(request):
if request.method=='POST':
form=GentForm(request.POST)
if form.is_valid():
data=form.cleaned_data
newgent=Gent(
pub_date=datetime.datetime.now(),
full_name=data['full_name'],
company_name=data['company_name'],
services=data['services'],
e_mail=data['e_mail'],
address=data['address'],
city=data['city'],
state=data['state'],
phone_no=data['phone_no'])
invite=newgent.save()
send_mail(Subject, message.render(Context()),from_email,[invite.e_mail])
return HttpResponse('Thanks. Kindly check your mail.')
else:
return HttpResponse('Kindly fill form.')
else:
return render_to_response('ment.html',{'GentForm':GentForm},context_instance=RequestContext(request))
How can I fix this?
The Model.save method has a return value of ‘None’. So ‘invite’ after invite=newgent.save() is None. Instead of
you should do
and then