def home(request): '''Homepage''' if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): form.save() # send a notification email to the administrator sender = '*****@*****.**' receivers = [mail for (_, mail) in settings.ADMINS] message = "[00001] New mail: " + form.cleaned_data[ 'email'] + " " + str(datetime.datetime.now()) try: smtpObj = smtplib.SMTP('localhost') smtpObj.sendmail(sender, receivers, message) print("Successfully sent email") except (smtplib.SMTPException, smtplib.ConnectionRefusedError): print("Error: unable to send email") else: form = ContactForm() # Topic list to display in the navgation bar topics = Topic.objects.all() return render(request, 'home/home.html', locals())
def home(request): '''Homepage''' if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): form.save() # send a notification email to the administrator sender = '*****@*****.**' receivers = [mail for (_,mail) in settings.ADMINS] message = "[00001] New mail: " + form.cleaned_data['email'] + " " + str(datetime.datetime.now()) try: smtpObj = smtplib.SMTP('localhost') smtpObj.sendmail(sender, receivers, message) print("Successfully sent email") except (smtplib.SMTPException, smtplib.ConnectionRefusedError): print("Error: unable to send email") else: form = ContactForm() # Topic list to display in the navgation bar topics = Topic.objects.all() return render(request, 'home/home.html', locals())
def post(self, request): form = ContactForm(request.POST) if form.is_valid(): form.save() return redirect('/contact') args = {'form': form} return render(request, self.template_name, args)
def contact_View(request): if request.method =='POST': form = ContactForm(request.POST) if form.is_valid(): form.save(commit=True) return redirect('home') else: form =ContactForm() return render(request,'home/contact.html', {'form':form})
def index(request): if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): form.save() return redirect("home") else: form = ContactForm() context = {"form": form} return render(request, "service/index.htm", context)
def index(request): testimonial = Testimonial.objects.all() if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): form.save() return redirect("home") else: form = ContactForm() context = {"form": form, "tests": testimonial} return render(request, 'home/index.htm', context)
def contact(request): if request.method == "GET": contactform = ContactForm() context = {'contactform': contactform} return render(request, 'home/contact.html', context) if request.method == "POST": contactform = ContactForm(request.POST) if contactform.is_valid(): contactform.save() print(contactform) return render(request, 'home/contact.html')
def Contact(request): form = ContactForm() if request.method == "POST": form = ContactForm(request.POST) confirm = False if form.is_valid(): form.save() confirm = True return render(request, "contact.html", {'form': form, 'confirm': confirm}) else: return render(request, "contact.html", {"form": form})
def partner(request): if request.method == 'POST': form2 = ContactForm(request.POST, request.FILES or None) print(form2.errors) if form2.is_valid(): form2.save() #return redirect('partner') subject= form2.cleaned_data.get('subject') message=form2.cleaned_data.get('mssg') recepient=form2.cleaned_data.get('email') send_mail(subject, message, recepient, [ EMAIL_HOST_USER], fail_silently = False) return render(request, 'home/success.html', {'recepient': recepient}) else: form2 = ContactForm() context = {'form2' : form2} return render(request,'home/partner.html',context)
def post(self, request): form = ContactForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.date = timezone.now() post.save() return redirect('about') else: form = ContactForm() return render(request, self.template_name, {'form': form})
def test_valid_contact_form_data(self): form = ContactForm({ 'name': "Test User", 'email': "*****@*****.**", 'message': "Here is my test message", }) self.assertTrue(form.is_valid()) message = form.save() self.assertEqual(message.name, "Test User") self.assertEqual(message.email, "*****@*****.**") self.assertEqual(message.message, "Here is my test message") self.assertTrue('contacted')