Answer the question
In order to leave comments, you need to log in
What is the best way to organize many different forms on a page?
Hello!
There was a problem of placement of set of forms on different pages. Each form is part of a separate application (app) with its own paths. Almost all applications are their own, some are third-party.
It seems to be an obvious solution - to use inclusion-tags , but, unfortunately, I did not find good implementation examples, and a lot of questions arose, two main ones:
1. How to write a tag correctly?
If all processing is placed in the view, then only the form render remains for the tag:
@register.inclusion_tag('core/my/form.html')
def my_form():
return {'form': MyForm()}
but in this case it is not clear how incorrectly filled fields in the form will be highlighted, because it will be rendered empty every time. Answer the question
In order to leave comments, you need to log in
The idea to give forms through rendering is not very correct at all. This was true 10 years ago, where there were not a lot of forms on the page, and one form - one view worked perfectly. I recommend sending and passing forms via json/ajax, and for rendering use the client side and javascript with jquery/reactjs/vuejs/angularjs... Yes, this probably crosses out your inner world a little, but it just so happened that today it is so .
On the other hand, everything becomes simpler - write templates with your own bunch of forms, write endpoint routes for ajax with json receiving and issuing, the rest is client side. And it’s easier to test, and to keep a bunch of forms on one page, and it’s also easier to send them, in the end it will even work faster, since you don’t need to drive the entire page every time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question