Ran into a slight problem implementing that one Rajesh - getting the form to submit the form data wasn't quite right with the simple contect processor you described.
I then hit on the obvious solution: implement the redirection using the form HTML. Changing that snippet to use /contact/thanks/ did the trick. Thanks for allt he help! 10000 On Jul 3, 4:52 pm, Rajesh D <rajesh.dha...@gmail.com> wrote: > On Jul 3, 8:57 am, 10000angrycats <christopher.liversi...@gmail.com> > wrote: > > > > > Great suggestion Rajesh. > > > I've shifted everything into a custom context processor and > > everythign's runnign well, with the view showing and emailing from any > > page, however there's a final step I'm looking to resolve: returning > > the HttpResponseRedirect within the context processor fails silently. > > > The context_processor.py file is this: > > > def login_form(request): > > from website.contact.forms import ContactForm > > from django.core.mail import send_mail > > from django.http import HttpResponseRedirect > > if request.method == 'POST': > > form= ContactForm(request.POST) > > ifform.is_valid(): > > cd =form.cleaned_data > > send_mail( > > cd['subject'], > > cd['message'], > > cd.get('email', 'nore...@foo.com'), > > ['cont...@foo.com'], > > ) > > return HttpResponseRedirect('/contact/thanks/')#Not > > redirecting > > yet. > > else: > > form= ContactForm( > > initial={'subject': 'Here's a suggestion...'} > > ) > > return {'form':form} > > > There's little documentation I've found on this one. Any help > > appreciated. > > You need to break that into two pieces because the context processor > can not handle submissions (i.e. your POSTed data). > > 1. Leave the "defcontact(request)" view from your original post as > is. It should be able to handle posted data. > > 2. In yourcontactprocessor just return the initialformi.e. the > part of the "else" like this:form= ContactForm(initial={'subject': 'Here's a > suggestion...'}) > return {'form':form} > > In the template tag that renders theform, change the action attribute > to post to thecontactview from #1 above. > > In other words, you are using the context processor to add an emptyformto > each request's template context. But the postedformalways > goes to a fixed view that knows how to handle the post and do your > redirect. > > -RD --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---