def contact(request): if request.method == 'POST': # 已经提交表单 form = ContactForm(request.POST) # request.POST是一个字典 if form.is_valid(): # 表单有效 cd = form.cleaned_data try: send_mail( subject = cd['subject'], # 主题 message = 'Message:\n' + cd['message'], # 正文 from_email = cd.get('email', '*****@*****.**'), # 寄信人 recipient_list = ['*****@*****.**'], # 收信人列表 ) return HttpResponseRedirect(url_prefix+'/contact/thanks/') except: print 'Can not send mail' else: # 未提交表单 form = ContactForm( initial = { 'subject': '测试主题', 'email': '*****@*****.**', 'message': '在此我通过对表单赋初值来实现此效果', } ) return render_to_response( 'contact/contact_form.html', {'form': form} )
def contact(request): errors = [] if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data send_mail( cd['subject'], cd['message'], cd.get('email', '*****@*****.**'), ['*****@*****.**'], ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm(initial={'subject': 'I love your site!'}) return render_to_response('contact_form.html',{'form': form}) #if not request.POST.get('subject', ''): # errors.append('Enter a subject.') #if not request.POST.get('message', ''): # errors.append('Enter a message.') #if request.POST.get('email') and '@' not in request.POST['email']: # errors.append('Enter a valid e-mail address.') #if not errors: # send_mail( # request.POST['subject'], # request.POST['message'], request.POST.get('email', '*****@*****.**'), ['*****@*****.**'], # ) # return HttpResponseRedirect('/contact/thanks/') #return render_to_response('contact_form.html',{ # 'errors': errors, # 'subject': request.POST.get('subject', ''), # 'message': request.POST.get('message', ''), # 'email': request.POST.get('email', ''), #})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data send_mail(cd['subject'],cd['message'],cd.get('email','*****@*****.**'),['*****@*****.**']) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm(initial={'subject':'I love your site!'}) return render_to_response('contact_form.html',{'form':form},context_instance=RequestContext(request))
def contact(request): if request.method == 'GET': form = ContactForm(request.GET) if form.is_valid(): cd = form.cleaned_data # call send_email() return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm( initial={'email':'[email protected]'} #not worked! ) return render_to_response('contact_form.html', {'form': form})
def contact(request): #errors = [] if request.method == 'POST': form = ContactForm(requst.POST) if form.is_valid(): cd = form.cleaned_data send_mial( cd['subject'], cd['message'], cd.get('email', '*****@*****.**'), ['*****@*****.**'], )
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data send_mail( cd['subject'], cd['message'], cd.get('email', '*****@*****.**'), ['*****@*****.**'], ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm() return render_to_response('contact_form.html', {'form': form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_vaild(): cd = form.cleaned_data send_mail( cd['subject'], cd['message'], cd.get('email', '*****@*****.**'), ['*****@*****.**'], ) return HttpResponseRedirect('/contact/thanks') else: form = ContactForm(initial={'subject': 'have fun'}) return render_to_response('contact_form.html', {'form': form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data send_mail( cd['subject'], cd['message'], cd.get('email', '*****@*****.**'), ['*****@*****.**'], ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm() return render_to_response('books/contact_form.html', {'form': form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data send_mail( request.POST['subject'], request.POST['message'], request.POST.get('e-mail', '*****@*****.**'), ['*****@*****.**'], ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm(initial = {'subject':'Мне очень нравится ваш сайт!'}) return render_to_response('contact_form.html', {'form': form})
def contact(request): errors = [] if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data send_mail( cd['subject'], cd['message'], cd.get('email', '*****@*****.**'), ['*****@*****.**'], ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm(initial={'subject': 'I love your site!'}) return render(request, 'contact_form.html', {'form': form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data # send_mail( # cd['subject'], # cd['message'], # cd.get('email', '*****@*****.**'), # ['*****@*****.**'], # ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm( initial={'subject': 'I love your site!'} ) return render(request, 'contact_form.html', {'form': form})
def contact(request): if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data """ send_mail( cd['subject'], cd['message'], cd.get('email', '*****@*****.**'), ['*****@*****.**'], ) """ return HttpResponseRedirect("/contact/thanks/") else: form = ContactForm(initial={"subject": "I love your site!"}) return render_to_response("contact_form.html", {"form": form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data send_mail( cd['subject'], cd['message'], cd.get('email', '*****@*****.**'), ['*****@*****.**'], ) messages.success(request, "Your email is {}".format(cd['email'])) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm( # initial={'subject': 'I love your site!'} ) return render(request, 'contact_form.html', {'form': form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data # send_mail(subject, message, from_email, recipient_list, # fail_silently=False, auth_user=None, auth_password=None, # connection=None) send_mail( cd['subject'], cd['message'], cd.get('email', '*****@*****.**'), ['*****@*****.**'], auth_user="******", auth_password="******", connection="smtp.gmail.com", ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm() return render_to_response('contact_form.html', {'form': form})
if form.is_valid(): cd = form.cleaned_data send_mial( cd['subject'], cd['message'], cd.get('email', '*****@*****.**'), ['*****@*****.**'], ) """ if not request.POST.get('subject', ''): errors.append('Enter a subject.') if not request.POST.get('message', ''): errors.append('Enter a message.') if request.POST.get('email') and '@' not in request.POST['email']: errors.append('Enter a valid e-mail address.') if not errors: send_mail( request.POST['subject'], request.POST['message'], request.POST.get('email', '*****@*****.**'),['*****@*****.**'], ) """ return HttpResponseRedirect('/contact/thanks') else: form = ContactForm(initial={'subject': 'I love your site!'}) return render_to_response('contact_form.html', {'form': form}) """ return render_to_response('contact_form.html', {'errors': errors, 'subject':request.POST.get('subject', ''), 'message': request.POST.get('message', ''), 'email': request.POST.get('email', ''), }) """