【发布时间】:2015-09-12 15:31:42
【问题描述】:
我的views.py 上有这个方法:
def contact_us(request):
form = ContactUsForm()
d = {'form': form}
if request.method == 'POST':
form = ContactUsForm(request.POST)
if form.is_valid():
Contact.objects.create(
first_name=form.cleaned_data['first_name'],
last_name=form.cleaned_data['last_name'],
email=form.cleaned_data['email'],
message=form.cleaned_data['message'],
)
try:
send_mail(first_name,last_name,email,message,['kristian.koci@gmail.com'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
d['message'] = _('Thank You! We will contact you shortly')
else:
d['form'] = form
return render_to_response('profiles/contact_us.html', d,
context_instance=RequestContext(request))
这是网址:
http://beta.contratalos.com/profiles/contact_us/
我想将该消息发送给我在sned_mail 方法中指定的收件人。
但是每次我尝试它都会抛出这个错误:
NameError: global name 'first_name' is not defined
File "apps/profiles/views.py", line 737, in contact_us
send_mail(first_name,last_name,email,message,['kristian.koci@gmail.com'])
有什么想法吗?
提前致谢!
【问题讨论】: