Answer the question
In order to leave comments, you need to log in
How to run more than two views on the same url?
Tell me, please, how can I combine the execution of several views on one page?
For example, you need to add the contact form django-contact-form.readthedocs.org
to the main page
The views.py code in the index:
def index(request):
args = {}
args.update(csrf(request))
return render_to_response('index.html', args)
class ContactFormView(FormView):
form_class = ContactForm
template_name = 'contact_form/contact_form.html'
def form_valid(self, form):
form.save()
return super(ContactFormView, self).form_valid(form)
def get_form_kwargs(self):
kwargs = super(ContactFormView, self).get_form_kwargs()
kwargs.update({'request': self.request})
return kwargs
def get_success_url(self):
return reverse('contact_form_sent')
Answer the question
In order to leave comments, you need to log in
If the placement of the form itself on the main page can be understood, then the processing is no longer. This is wrong and should not be wanted.
Make a separate view to process the contact form. Let her redirect back to the main page. Or sent by Ajax so that the user does not leave. Visually it will be the same, but more correct from the point of view of common sense.
Or are you interested in this question purely theoretically?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question