def contacto(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): titulo = 'Mensaje desde el Sistema Cesic' contenido = form.cleaned_data['mensaje']+"\n" contenido+='Comunicarse a: '+form.cleaned_data['correo'] correo = EmailMessage (titulo ,contenido,to=['*****@*****.**']) correo.send() return HttpResponseRedirect('/contacto') else: form=ContactForm() return render_to_response('contacto.html', {'form':form,},context_instance=RequestContext(request))
def get(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) context['active'] = 'contact' contact_form = ContactForm() context['form'] = contact_form return self.render_to_response(context)
def post(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) context['active'] = 'contact' recipients = [mail for name, mail in ADMINS] form = ContactForm(request.POST) if form.is_valid(): subject = form.cleaned_data['subject'] email = form.cleaned_data['email'] message = form.cleaned_data['message'] send_mail(subject, message, email, recipients) else: contact_form = ContactForm(request.POST) context['form'] = contact_form return self.render_to_response(context)