0

我想向在我的 django 网站上填写表格的每个用户发送邮件。为它编写代码后,我收到以下错误。我一直试图找出错误的原因,但没有成功。以下是我的代码:

AttributeError at /meek/
'NoneType' object has no attribute 'e_mail'

意见

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))

我怎样才能解决这个问题?

4

1 回答 1

0

Model.save 方法的返回值为“None”。所以在invite=newgent.save() 之后的'invite' 是None。代替

invite=newgent.save()

你应该做

newgent.save()

接着

send_mail(Subject, message.render(Context()),from_email,[newgent.e_mail])
于 2013-01-01T13:34:26.530 回答