def contact_us(request): contact_form = ContactForm() if request.method == "POST": if contact_form.is_valid(): print("is valis") email_id = request.POST.get('email_id', '') subject = request.POST.get('subject', '') body = request.POST.get('body', '') ctx= { 'email_id': email_id, 'subject': subject, 'body': body } template = get_template('email_template.html') email_content = template.render(context=ctx) email = EmailMessage( "Someone is trying to contact...", email_content, 'Django Blog', [DEFAULT_FROM_EMAIL], headers={"Reply-To": email_id} ) email.send() return redirect('blog:home') else: return redirect('blog:contact') return render(request, 'contact.html', {"contact_form":contact_form})
def index(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): form.save() name = form.cleaned_data['name'] sender = form.cleaned_data['sender'] phone = form.cleaned_data['phone'] message = form.cleaned_data['message'] from_email = settings.EMAIL_HOST_USER to_email = [from_email,] contact_subject = "Message from %s is arrived" % name contact_message = "message: %s \nsender: %s \nEmail: %s \nphone: %s" %(message, name, sender, phone) send_mail( contact_subject, contact_message, from_email, to_email, fail_silently=False) return HttpResponseRedirect('/contact/') else: form = ContactForm() params = { 'form':form, } return render(request, 'blog/index.html', params)
def contact(): form = ContactForm() if request.method == "POST": if not form.validate_on_submit(): email = request.form["email"] title = request.form["title"] name = request.form["name"] surname = request.form["surname"] content = request.form["email_content"] message = Mail( from_email=os.environ.get("MAIL_DEFAULT_SENDER"), to_emails=os.environ.get("MAIL_DEFAULT_RECEIVER"), subject=f"From {email}. Subject: {title}", html_content= f"<strong>Message from: <p>{name} {surname}.</p><p>MESSAGE:</p> <p>{content}</p> </strong>", ) try: sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY")) response = sg.send(message) print(response.status_code) print(response.body) print(response.headers) flash("Message Send.", "success") return redirect("/contact/") except Exception as e: print(f"error", e.body) return render_template("/contact_form.html")
def contact_us(request): if request.method == "GET": menu_list = Menu.objects.filter(parent=None, is_active=True) event_list = Event.objects.filter( is_active=True).order_by('-start_date')[0:1] footer_events = Event.objects.filter( is_active=True).order_by('-start_date')[0:4] return render( request, "site/contact.html", { 'menu_list': menu_list, 'footer_events': footer_events, 'event_list': event_list }) validate_contact = ContactForm(request.POST) errors = {} if validate_contact.is_valid(): contact = validate_contact.save() try: send_mail(contact.name, contact.message, contact.email, ['*****@*****.**'], fail_silently=False) data = {"data": 'Thank you, For Ur Message.!', "error": False} return JsonResponse(data) except Exception: data = {"data": 'Server Error.!', "error": True} return JsonResponse(data) else: for k in validate_contact.errors: errors[k] = validate_contact.errors[k][0] return JsonResponse(errors)
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] sender = form.cleaned_data['sender'] cc_myself = form.cleaned_data['cc_myself'] if cc_myself: recipients = [sender] send_mail(subject, message, sender, recipients) message = "From: %s\n\n%s" % (sender, message) mail_managers(subject, message) return redirect('blog.views.contact_thanks') else: form = ContactForm() return render_to_response('blog/contact.html', { 'form': form, })
def test_contact_form_is_not_valid_with_bad_information(self): form = ContactForm(data={ 'name': 'test', 'email': '*****@*****.**', 'message': 'test message', }) self.assertFalse(form.is_valid())
def contactView(request): if request.method == 'POST': form = ContactForm(request.POST) # Если форма заполнена корректно, сохраняем все введённые пользователем значения if form.is_valid(): subject = form.cleaned_data['subject'] sender = form.cleaned_data['sender'] message = form.cleaned_data['message'] print(subject, sender, message) # Если пользователь захотел получить копию себе, добавляем его в список получателей try: email = EmailMessage(subject, sender + '\n' + message, to=['*****@*****.**']) email.send() except BadHeaderError: # Защита от уязвимости print('lol') return HttpResponse('Invalid header found') # Переходим на другую страницу, если сообщение отправлено return HttpResponseRedirect(request.META.get('HTTP_REFERER')) else: return HttpResponseRedirect(request.META.get('HTTP_REFERER')) else: return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
def contact(request): """ 留言视图 :param request: :return: """ # 表单提交时 if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] email = form.cleaned_data['email'] subject = form.cleaned_data['subject'] content = form.cleaned_data['content'] verify_code = form.cleaned_data['check_code'] # 表单中的验证码 correct_code = request.session.get('CheckCode', None) if correct_code and verify_code.upper() == correct_code.upper(): cont = Contact(name=name, email=email, subject=subject, content=content) cont.save() result = {'result': '我已经收到你的消息了,我会尽快查看消息!'} return JsonResponse(result) else: result = {'result': '验证码错误, 请重新填写!'} return JsonResponse(result) else: return JsonResponse({'result': '服务器异常,请稍后重试'}) # get请求页面时 else: form = ContactForm() return render(request, 'blog/contact.html', {'form': form})
def contactupdate(request, contact_ID): mycontact = Contacts.objects.get(contact_ID = contact_ID) form = ContactForm(request.POST, instance = mycontact) if form.is_valid(): form.save() return redirect('/contactlist') return render(request, "blog/edit_contact.html", {'mycontact':mycontact})
def normalisation(request): if request.method == 'POST': # S'il s'agit d'une requête POST form = ContactForm(request.POST, request.FILES) # Nous reprenons les données if form.is_valid(): # Nous vérifions que les données envoyées sont valides global k, n, tab_normalise, datafile # recuperation de données k et n k = int(form.cleaned_data['k']) n = float(form.cleaned_data['n']) #datafile = request.FILES['docfile'].name datafile = "spambase.data" norm = Normalizer() data_matrix = norm.load_csv(datafile) tab_champs = norm.separation_champs(data_matrix) tab_normalise = norm.normalisation(tab_champs) tab_normalise_local = [] i = 0 for i in range(58): tab_normalise_local.append([]) i=0 for tab in tab_normalise: tab_normalise_local[i].append([min(tab), max(tab), numpy.mean(tab), variance(tab)]) i+=1 return render(request, 'blog/normalisation.html', locals()) else: # Si ce n'est pas du POST, c'est probablement une requête GET form = ContactForm() # Nous créons un formulaire vide return render(request, 'blog/accueil.html', locals())
def contact_form(request): contact_form = ContactForm() if request.method == 'POST': # form = contact_form(data=request.POST) if contact_form.is_valid(): print("is valid form") email_id = request.POST.get('email_id', '') subject = request.POST.get('subject', '') email_body = request.POST.get('email_body') ctx = { 'email_id': email_id, 'subject': subject, 'email_body': email_body, } template = get_template('email_template.html') email_content = template.render(context=ctx) email = EmailMessage("Someone is tryng to contact...", email_content, 'Django Blog', [DEFAULT_FROM_EMAIL], headers={'repy-to': email_id}) email.send() return redirect('blogs:home_pg') else: return redirect('blogs:contact_pg') return render(request, 'blog/contact.html', {'form': contact_form})
def contact(request): # check if any form data that needs to be emailed if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): subject = 'New Member Sign up' message = ("Name: " + form.cleaned_data['name'] + ", Organisation: " + form.cleaned_data['organisation'] + ", Email: " + form.cleaned_data['email']) sender = settings.EMAIL_FROM recipient = [form.cleaned_data['email']] send_mail(subject, message, sender, recipient) # Always return an HttpResponseRedirect after successfully dealing # with POST data. This prevents data from being posted twice if a # user hits the Back button. return HttpResponseRedirect(reverse('blog:thanks')) else: form = ContactForm() context = { 'active_page': "contact", 'form': form, } return render(request, 'blog/contact.html', context)
def ContactView(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): return render(request, 'contact.html', {'form': form}) 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(): name = form.cleaned_data['name'] email = form.cleaned_data['email'] form = ContactForm() return render(request,"page_src/contact.html", {'form':form})
def contact(request): if request.method == "POST": contact_form= ContactForm(request.POST) if contact_form.is_valid(): contact_form.save() return HttpResponseRedirect('/blog/thanks') else: contact_form = ContactForm() return render(request, 'blog/contact.html', {'contact_form': contact_form})
def Contact(request): form = ContactForm(request.POST or None) if form.is_valid(): topic = form.cleaned_data['topic'] text = form.cleaned_data['text'] sender = form.cleaned_data['sender'] sending = True return render(request, 'contact.html', locals())
def view_page(request, category_name_slug): # Create a context dictionary which we can pass to the template rendering engine. context_dict = {} # Can we find a category name slug with the given name? # If we can't, the .get() method raises a DoesNotExist exception. # So the .get() method returns one model instance or raises an exception. page = Page.objects.get(slug=category_name_slug) context_dict['page'] = page # A HTTP POST? if request.method == 'POST': form = ContactForm(request.POST) # Have we been provided with a valid form? if form.is_valid(): # Save the new category to the database. form.save(commit=True) #name = form.cleaned_data['name'] #subject = form.cleaned_data['subject'] #message = "Message Sent by you to Rustamehind " + "Name: " + name + " " + form.cleaned_data['message'] #sender = form.cleaned_data['sender'] #cc_myself = form.cleaned_data['cc_myself'] #recipients = ['*****@*****.**'] #if cc_myself: #recipients.append(sender) #send_mail(subject, message, sender, recipients) subject, from_email = form.cleaned_data['subject'], form.cleaned_data['sender'] to = from_email to2 = '*****@*****.**' text_content = form.cleaned_data['message'] html_content = '<p>Contact Form Rustam-e-hind<br></p>' + "Name: " + form.cleaned_data['name'] + "<br>Subject: " + form.cleaned_data['subject'] + "<br>From: " + form.cleaned_data['sender'] + "<br>Message: "+ form.cleaned_data['message'] msg = EmailMultiAlternatives(subject, text_content, from_email, [to,to2]) msg.attach_alternative(html_content, "text/html") msg.send() # Now call the index() view. # The user will be shown the homepage. return index(request) else: # The supplied form contained errors - just print them to the terminal. print form.errors else: # If the request was not a POST, display the form to enter details. form = ContactForm() # Bad form (or form details), no form supplied... # Render the form with error messages (if any). return render(request,"view_page.html", { 'page': context_dict['page'], 'pages': Page.objects.all(), 'form': form })
def test_contact_form_is_valid_with_good_information(self): form = ContactForm( data={ 'name': 'test', 'email': '*****@*****.**', 'subject': 'test subject', 'message': 'test message', }) self.assertTrue(form.is_valid())
def contact(): form = ContactForm() if request.method == "POST": if not form.validate_on_submit(): email = request.form["email"] title = request.form["title"] name = request.form["name"] content = request.form["email_content"] flash("Message Send.", "success") return render_template("/contact.html")
def contact2(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valiad(): 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_form2.html', {"form": form}, context_instance = RequestContext(request)) return render_to_response('contact_form2.html', {"form": form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): sujet = form.cleaned_data['sujet'] message = form.cleaned_data['message'] envoyeur = form.cleaned_data['envoyeur'] renvoi = form.cleaned_data['renvoi'] return HttpResponseRedirect('/blog/') else: form = ContactForm() return render(request, 'blog/contact.html', {'title': 'Contacter nous!', 'form': form})
def contactView(request): form = ContactForm(request.POST) if request.method == 'POST' and form.validate(): subject = form.subject.data message = "{0}\n-{1}".format(form.message.data, form.name.data) sender = form.email.data recipients = ['*****@*****.**'] send_mail(subject, message, sender, recipients) return HttpResponseRedirect(reverse('thanks')) template = loader.get_template('contact_me.html') context = {'form':form} return HttpResponse(template.render(context, request))
def contactEmail(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): asunto = 'Este es un mensaje de mi blog en DJANGO' mensaje = form.cleaned_data['msj'] mail = EmailMessage(asunto, mensaje, to = ['*****@*****.**']) mail.send() return HttpResponseRedirect('/') else: form = ContactForm() return render_to_response('email.html', {'form': form}, context_instance = RequestContext(request))
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): email_address = form.cleaned_data['email_address'] subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] send_mail(email_address, subject, message, ['*****@*****.**'], fail_silently=False) return HttpResponseRedirect('/blog/') 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(): sujet = form.cleaned_data['sujet'] message = form.cleaned_data['message'] envoyeur = form.cleaned_data['envoyeur'] renvoi = form.cleaned_data['renvoi'] envoi = True else: form = ContactForm() return render(request, 'blog/HTML/contact.html', locals())
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['name'], cd.get('email', '*****@*****.**'), ['*****@*****.**']) return HttpResponseRedirect('/blog/about/') else: form = ContactForm() return render(request, 'blog/contact.html', {'form': form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): form.save(commit=True) return index (request) else: print (form.errors) else: form = ContactForm() return render(request, 'blog/contact_form.html', {'form':form})
def contact(request, template="contact.html"): if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): contact = form.save() send_mail_with_template( u"Yeni iletişim maili", settings.MY_MAIL, "mails/newmessage.html", {"contact": contact} ) messages.add_message(request, messages.SUCCESS, u"Tamamdır") return redirect("contact") else: form = ContactForm() ctx = {"form": form} return render(request, template, ctx)
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): # 只打印查看提交的结果是否正确 cd = form.cleaned_data print(cd) # 提交成功后跳转 home 页面,通过 spacename 和 name 值指定页面 return redirect('blog:home') else: # 不是 POST 方式则重定向到空白页面 form = ContactForm() # return render(request, 'blog/contact.html', None) return render(request, 'blog/contact.html', locals())
def postArticle(request): if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): cd = form.cleaned_data p1 = Articles(h1=cd['h1'], content=cd['content'], author_id=cd['author'], category_id=cd['category']) p1.save() return HttpResponseRedirect('/postArticle/thanks') else: if request.META.get("HTTP_REFERER") and request.META.get("HTTP_REFERER").find("invite") != -1: form = ContactForm() else: return HttpResponseRedirect('/invite/') return render(request, 'mainTem/postArticle.html', {"form": form})
def contact(request): if request.method == 'GET': form = ContactForm() else: form = ContactForm(request.POST) if form.is_valid(): subject = form.cleaned_data['subject'] from_email = form.cleaned_data['from_email'] message = form.cleaned_data['message'] try: send_mail(subject, message, from_email, ['*****@*****.**']) except BadHeaderError: return HttpResponse('Invalid header found.') return redirect('contact') return render(request, "blog/blog_contact.html", {'form': form})
def emailview(request): if request.method == 'GET': form = ContactForm() else: form = ContactForm(request.POST) if form.is_valid(): subject = form.cleaned_data['subject'] from_email = form.cleaned_data['from_email'] message = form.cleaned_data['message'] try: send_mail(subject, message, from_email, ['*****@*****.**']) except BadHeaderError: return HttpResponse('Invalid header found.') return redirect('success') return render(request, "blog/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', '*****@*****.**'), ['*****@*****.**'], ) return HttpResponseRedirect('/contact/thanks/') else: form = ContactForm() return render(request, 'contact.html', {'form': form})
def get(self, request, *args, **kwargs): context = {} context['form'] = ContactForm() question = request.GET.get('q') if question is not None: search_articles = Post.objects.filter( title__istartswith=question) | Post.objects.filter( text__icontains=question) # формируем строку URL, которая будет содержать последний запрос # Это важно для корректной работы пагинации context['last_question'] = '?q=%s' % question current_page = Paginator(search_articles, 5) page = request.GET.get('page') try: context['post_list'] = current_page.page(page) except PageNotAnInteger: context['post_list'] = current_page.page(1) except EmptyPage: context['post_list'] = current_page.page( current_page.num_pages) return render(request, template_name=self.template_name, context=context)
def VistaContacto(request): if request.method == 'POST': form = ContactForm(request.POST) print('si es un post') if form.is_valid(): print('si es valido') form.save(commit=True) print('si se ha salvado') return HttpResponseRedirect(reverse('index')) else: print(form.errors) else: print('no es unn post') return render(request,'index.html')
def contact_us(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): sender_name = form.cleaned_data['name'] sender_email = form.cleaned_data['email'] message = "{0} has sent you a new message:\n\n{1}".format( sender_name, form.cleaned_data['message']) send_mail('New Enquiry', message, sender_email, ['*****@*****.**']) return HttpResponse('Thanks for contacting us!') else: form = ContactForm() return render(request, 'blog/contact-us.html', {'form': form})
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): msg = Message() msg.sujet = form.cleaned_data['sujet'] msg.message = form.cleaned_data['message'] msg.email = form.cleaned_data['email'] msg.save() envoi = True else: form= ContactForm() return render(request,'blog/contact.html',locals())
def contact(request): if request.method == 'POST': # S'il s'agit d'une requête POST form = ContactForm(request.POST) # Nous reprenons les données if form.is_valid(): # Nous vérifions que les données envoyées sont valides # Ici nous pouvons traiter les données du formulaire sujet = form.cleaned_data['sujet'] message = form.cleaned_data['message'] envoyeur = form.cleaned_data['envoyeur'] renvoi = form.cleaned_data['renvoi'] # Nous pourrions ici envoyer l'e-mail grâce aux données que nous venons de récupérer envoi = True else: # Si ce n'est pas du POST, c'est probablement une requête GET form = ContactForm() # Nous créons un formulaire vide return render(request, 'blog/contact.html', locals())
def contact_us(request): try: if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): send_email(form.cleaned_data) messages.success(request, 'Your response has been recorded') else: form = ContactForm() except: messages.error(request, 'Please configure your email settings.') return render(request, 'blog/contact.html', { 'page': 'contact', 'form': form })
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'] email = form.cleaned_data['renvoi'] name = form.cleaned_data['name'] try: send_mail(name, topic, message, email, ['*****@*****.**']) except BadHeaderError: return HttpResponse('Invalid header found.') else: # GET form = ContactForm() return render(request, 'contact.html', locals())
def clear(request): form = ContactForm() messages.error(request, 'Fields cleared successfully') return render(request, 'blog/contact.html', { 'page': 'contact', 'form': form })
def contact(request): if request.method =='POST': form = ContactForm(request,POST) if form.is_valid(): sujet = forms.cleaned_data['sujet'] message = forms.cleaned_data['message'] envoyeur = forms.cleaned_data['emvoyeur'] renvoi = forms.cleaned_data['renvoi'] envoi = True else: form = ContactForm return render(request, 'blog/tpl_app/tpl_contact_form.html', locals())
def contactUs(request): contact_form = ContactForm(request.POST or None) context = { "title": "Contact Us", "content": "Welcome to the contact page", "form": contact_form } # print(contact_form) if contact_form.is_valid(): print(contact_form.cleaned_data) # if request.method == "POST": # # print(request.POST) # # print(type(request)) # # print(request.POST["csrfmiddlewaretoken"]) # # print(request.POST.get("fullname")) # print(request.POST["fullname"],request.POST["email"],request.POST["content"]) return render(request, "contact/view.html", context)
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): #Ici nous pouvons traiter les données du formulaire sujet = form.cleaned_data['sujet'] message = form.cleaned_data['message'] envoyeur = form.cleaned_data['envoyeur'] renvoi = form.cleaned_data['renvoi'] #envoi de l'email grâce aux données que nous venons de récupérer envoi = True else: form = ContactForm() return render(request, 'blog/contact.html', locals())
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 blog!'}) return render_to_response('contact_form.html', context_instance=RequestContext( request, {'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 blog!'} ) return render_to_response('contact_form.html', context_instance=RequestContext(request, {'form': form}))
def contact(request): if request.method == 'POST': # S'il s'agit d'une requête POST form = ContactForm(request.POST) # Nous reprenons les données if form.is_valid( ): # Nous vérifions que les données envoyées sont valides # Ici nous pouvons traiter les données du formulaire sujet = form.cleaned_data['sujet'] message = form.cleaned_data['message'] envoyeur = form.cleaned_data['envoyeur'] renvoi = form.cleaned_data['renvoi'] # Nous pourrions ici envoyer l'e-mail grâce aux données que nous venons de récupérer envoi = True else: # Si ce n'est pas du POST, c'est probablement une requête GET form = ContactForm() # Nous créons un formulaire vide return render(request, 'blog/contact.html', locals())
def index(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): form.save() name = form.cleaned_data['name'] sender = form.cleaned_data['sender'] phone = form.cleaned_data['phone'] message = form.cleaned_data['message'] from_email = settings.EMAIL_HOST_USER to_email = [ from_email, ] contact_subject = "Message from %s is arrived" % name contact_message = "message: %s \nsender: %s \nEmail: %s \nphone: %s" % ( message, name, sender, phone) send_mail(contact_subject, contact_message, from_email, to_email, fail_silently=False) return HttpResponseRedirect('/contact/') else: form = ContactForm() params = { 'form': form, } return render(request, 'blog/index.html', params)
def contact(request): """Page containing a contact form for visitors trying to contact admins""" projects = Project.objects.all().order_by('name') if request.method == 'GET': form = ContactForm() else: form = ContactForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] subject = form.cleaned_data['subject'] from_email = form.cleaned_data['email'] message = form.cleaned_data['message'] subject = [subject, "No Subject"][subject == ""] final_message = "Sender's name: {name}\nSender's email: {from_email}\nSubject: {subject}\n\n\nMessage:\n\n{message}\n\n".format(**locals()) try: mail_admins("Contact form request", final_message) messages.success(request, "Your message was sent successfully! We'll get back to you as soon as we get the chance.") form = ContactForm() except BadHeaderError: return HttpResponse('Invalid header found.') return render(request, "blog/contact.html", locals(), context_instance=RequestContext(request))
def contact(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): sender = form.cleaned_data['sender'] cc_myself = form.cleaned_data['cc_myself'] subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] recipients = ['*****@*****.**'] if cc_myself: recipients.append(sender) send_mail(sender+':'+subject, message, '*****@*****.**', recipients) return HttpResponseRedirect(reverse('blog:thanks')) else: form = ContactForm() context = basic_context() context.update(form=form) return render(request, 'blog/contact.html', context)
def contact(request): messageSent = False if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] sender = form.cleaned_data['sender'] sendCopy = form.cleaned_data['sendCopy'] # Envoi du mail... messageSent = True form = ContactForm() else: form = ContactForm() return render(request, 'blog/contact.html', {'form': form, 'messageSent': messageSent})
def contact(request): msg = '' cf = ContactForm() if(request.method == 'POST'): #TODO send email cf = ContactForm(request.POST) if(cf.is_valid()): try: send_email('*****@*****.**', '*****@*****.**', 'Falsepixel: '+ cf.cleaned_data['name'] + ' wrote to you.', cf.cleaned_data['email'] +'<br>' +cf.cleaned_data['message']) msg = 'Message sent. Thanks.!' except: msg = 'Error sending msg. Try again please.' else: msg = 'Error sendin msg. Please verify fields.' t = get_template("contact.htm") c = RequestContext(request, {'form': cf, 'msg': msg}) return HttpResponse(t.render(c))
def contact_form(request): # A HTTP POST? if request.method == 'POST': form = ContactForm(request.POST) # Have we been provided with a valid form? if form.is_valid(): # Save the new category to the database. form.save(commit=True) #name = form.cleaned_data['name'] #subject = form.cleaned_data['subject'] #message = "Message Sent by you to Rustamehind " + "Name: " + name + " " + form.cleaned_data['message'] #sender = form.cleaned_data['sender'] #cc_myself = form.cleaned_data['cc_myself'] #recipients = ['*****@*****.**'] #if cc_myself: #recipients.append(sender) #send_mail(subject, message, sender, recipients) subject, from_email = form.cleaned_data['subject'], form.cleaned_data['sender'] to = from_email to2 = '*****@*****.**' text_content = form.cleaned_data['message'] html_content = '<p>Contact Form Rustam-e-hind<br></p>' + "Name: " + form.cleaned_data['name'] + "<br>From: " + form.cleaned_data['sender'] + "<br>"+ form.cleaned_data['message'] msg = EmailMultiAlternatives(subject, text_content, from_email, [to,to2]) msg.attach_alternative(html_content, "text/html") msg.send() # Now call the index() view. # The user will be shown the homepage. return index(request) else: # The supplied form contained errors - just print them to the terminal. print form.errors else: # If the request was not a POST, display the form to enter details. form = ContactForm() # Bad form (or form details), no form supplied... # Render the form with error messages (if any). return render(request, 'contact_form.html', {'form': form})
def blog(request, aid): '''博客文章详情页''' if request.method == 'GET': if aid: return __to_blog_view(request, __get_article(aid), ContactForm()) return HttpResponseRedirect('/index') else: # 保存文章评论 article = __get_article(request.POST.get("articleId")) form = ContactForm(request.POST, request) if form.is_valid(): email = form.cleaned_data["email"] nickname = form.cleaned_data["nickname"] content = form.cleaned_data["content"] comment = Comment(email=email, nickname=nickname, content=content, article=article) comment.save() return HttpResponseRedirect('/blog/' + request.POST["articleId"] + '#comment') else: return __to_blog_view(request, article, form)
def contact(request): correo_enviado='' recent = Post.objects.all()[:3] my_calendar = my_generated_calendar() try: my_contactform = ContactForm() except: my_contactform = ContactForm() if request.method == 'POST': # If the form has been submitted... contactform = ContactForm(request.POST) # A form bound to the POST data if contactform.is_valid(): name = contactform.cleaned_data['name'] surname = contactform.cleaned_data['surname'] phone = str(contactform.cleaned_data['phone']) subject = contactform.cleaned_data['subject'] comment = contactform.cleaned_data['comment'] email = [contactform.cleaned_data['email']] email = ['*****@*****.**'] email_text = str(contactform.cleaned_data['email']) sender = '*****@*****.**' message = ' Nombre:' + name + '\n Apellido:' + surname + '\n Telefono:' + phone + '\n Email: ' + email_text +'\n Consulta:' + comment correo_enviado = u'Su correo ha sido enviado, tan pronto...' #cc_myself = contactform.cleaned_data['cc_myself'] #if cc_myself: # recipients = recipients + ';' +cc_myself print "SUBJECT:",subject," \nMESSAGE", message,"\n SENDER ", sender, "\n EMAIL", email send_mail(subject, message, sender, email,fail_silently=False) return render_to_response('contact.html', RequestContext(request, { 'recent':recent, 'my_calendar':my_calendar, 'my_contactform':my_contactform, 'correo_enviado':correo_enviado }) )
def view_contactpage(request): contact_form = ContactForm(request.POST or None) if contact_form.is_valid(): form_name_or_title = contact_form.cleaned_data.get("name_or_title") form_email_adress = contact_form.cleaned_data.get("email_adress") form_contact_message = contact_form.cleaned_data.get("contact_message") subject = form_name_or_title from_email = form_email_adress contact_message = form_contact_message send_mail(subject+" - "+from_email, contact_message, from_email, ['*****@*****.**'], fail_silently=False) return render(request, 'blog/contact_sent.html', {}) context = { "contact_form": contact_form, } return render(request, 'blog/contact.html', context)
def contact(request): if request.method == 'POST': post = request.POST keys = post.keys() values = post.values() taille = range(0,len(keys)) form = ContactForm(request.POST) if form.is_valid(): sujet = form.cleaned_data['sujet'] message = form.cleaned_data['message'] envoyeur = form.cleaned_data['envoyeur'] renvoi = form.cleaned_data['renvoi'] # Nous pourions envoyer l'email grace aux donnees que nous venons de recupere envoi = True else : # Si la requete n'est pas du POST c'est donc du GET form = ContactForm() # Nous creons un formulaire vide return render(request, "blog/contact.html", locals())