def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm() return render(request, 'contact_form.html', {'form': form})
def contact(reqeust): if reqeust.method == 'POST': form = ContactForm(reqeust.POST) if form.is_valid(): cd = form.cleaned_data send_mail(cd['subject'],cd['message'],cd.get('email','*****@*****.**'),'*****@*****.**') return HttpResponseRedirect('/book/contact/thanks') else: form = ContactForm(initial={'subject':'I love your site'}) return render_to_response('books/contact_form.html',{'form':form},context_instance=RequestContext(reqeust))
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(reverse(thanks)) else: form = ContactForm() return render_to_response(get_template('contact_form.html'), {'form': form}, context_instance=RequestContext(request))
def contact(request): dic = {} dic.update(csrf(request)) if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data print cd return HttpResponseRedirect('/books/contact/thanks/') else: form = ContactForm() dic['form'] = form return render_to_response('contact.html', dic)
def contact(request): if request.method == 'post': form = ContactForm(request.POST) if form.is_valid(): topic = form.cleaned_data['topic'] message = form.cleaned_data['message'] sender = form.cleaned_data.get('sender', '*****@*****.**') send_mail('Feedback from your site,topic:%s' % topic, message, sender, ['*****@*****.**']) return HttpResponseRedirect('/contact/thanks') else: form = ContactForm() return render(request, 'contact.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', '*****@*****.**'), ['*****@*****.**'], ) 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(): #process form data topic = form.cleaned_data['topic'] message = form.cleaned_data['message'] sender = form.cleaned_data.get('sender', '*****@*****.**') #send_mail('Feedback from your site, topic: %s' % topic, # message, sender, ['*****@*****.**'],'', 'bushuevzi','2CnpS1Lov4M','smtp.mail.ru') return HttpResponseRedirect('./thanks') else: form = ContactForm(initial={'sender':'*****@*****.**'}) return render_to_response('contact.html', {'form':form})
def contact(request): errors = [] if request.method == 'POST': # If the form has been submitted... form = ContactForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass return HttpResponse('Thanks!') else: form = ContactForm() # An unbound form return render( request, 'contact.html', {'form': form, 'errors': errors} )
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(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() 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', '*****@*****.**'), ['*****@*****.**'], fail_silently=True) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm() return render_to_response('contact_form.html', {'form': form}, context_instance=RequestContext(request))
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': 'F**k you, You c**t'}) 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!'} #为字subject段添加初始值 ) return render(request, 'contact_form.html', {'form':form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): #con=form.save() topic = form.cleaned_data['topic'] message = form.cleaned_data['message'] sender = form.cleaned_data['sender'] send_mail('Feedback from your site: %s' % topic, message, sender, ['*****@*****.**'], fail_silently=False) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm() return render(request, 'contact.html', {'form': form})
def contact(request): if request.method == 'POST': #判断请求方法是否为post form = ContactForm(request.POST) #将想要发送的请求传到变量form中 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!', 'message': 'It is very beautiful' }) #如果不是post请求,就创建一个空表单,initial参数设置初始值 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', '*****@*****.**'), ['*****@*****.**'] # cd.get('email', <a class="reference external" href="mailto:'noreplay%40examble.com">'[email protected]</a>'), # [<a class="reference external"href="mailto:'siteowner%40examble.com">'[email protected]</a>'], ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm(initial={'subject': 'I love you'}) return render(request, 'books/contact_form.html', { 'form': form, 'ip_add': request.META['REMOTE_ADDR'] })
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): topic = form.cleaned_data['topic'] message = form.cleaned_data['message'] sender = form.cleaned_data.get('sender', '*****@*****.**') print(topic, message, sender) """ t=send_mail( 'Feedback from your site, topic: %s' % topic, message, sender, ['*****@*****.**'] ) """ #url = reverse('thanks', kwargs={'name': sender}) #return HttpResponseRedirect(url) #'/contact/thanks?name=aminul' return HttpResponseRedirect( reverse('ul_name', kwargs={'tst': sender})) else: form = ContactForm() return render_to_response('contact.html', {'form': form}, context_instance=RequestContext(request))
def contact(request): if request.method == 'POST': errors = [] form = ContactForm(request.POST) # context_dict = {'errors': errors, 'subject': request.POST.get('subject', ''), # 'message': request.POST.get('message', ''), 'email': request.POST.get('email', '')} # if not request.POST.get('subject', ''): # errors.append('请输入邮件主题') # return render(request, 'contact_form.html', context_dict) # return render_to_response() # if '@' not in request.POST.get('email') or not request.POST.get('email'): # errors.append('请输入有效的邮箱地址') # return render(request, 'contact_form.html', context_dict) # if not request.POST.get('message', ''): # errors.append('请输入邮件内容') # return render(request, 'contact_form.html', context_dict) if form.is_valid(): cd = form.cleaned_data try: send_mail( cd['subject'], cd['email'], cd['message'], ['*****@*****.**'], # cd.get('email', '*****@*****.**'), #['*****@*****.**'], ) # Contact.objects.create(subject=cd['subject'], email=cd['email'], message=cd['message']) contact = Contact() contact.subject = cd['subject'] contact.email = cd['email'] contact.message = cd['message'] contact.save() except smtplib.SMTPException as e: errors.append(u"邮件发送失败: %s" % e) return HttpResponse(errors) subject = cd['subject'] email = cd['email'] message = cd['message'] # return HttpResponseRedirect("/book/contact/thanks/?subject=%s&email=%s&message=%s" % (subject, email, message)) return thanks(request, args={ 'subject': subject, 'email': email, 'message': message }) # if not errors: # # try: # # send_mail(request.POST['subject'], # # request.POST['message'], # # request.POST.get('email', '*****@*****.**'), # # ['*****@*****.**'], # # ) # # return HttpResponseRedirect('/book/contact/thanks/') # # except : # # errors.append('邮件发送失败') else: form = ContactForm(initial={'subject': 'I love your site!'}) context_dict = {'form': form} return render(request, 'contact_form.html', context_dict)