To directly answer your first question, yes - I have separate views for each form, including separate URLs defined for each, all residing in the same views.py
file. In that particular situation, someone can either fill out the form for “Mode 1” or “Mode 2”, but never both. So part of my template looks something close to this:
<div id="create_mode_1">
<form action="{% url 'submit_mode_1' parent_id %}">
...
<button type="button">Mode 1</button>
</form>
</div>
and this form contains all the fields for mode 1, which is followed by:
<div id="create_mode_2">
<form action="{% url 'submit_mode_2' parent_id %}">
...
<button type="button">Mode 2</button>
</form>
</div>
with all the fields for mode 2.
Then, there’s a little bit of JavaScript / jQuery that shows or hides the right form based upon a radio button above this section on the page, and other code that submits the form as an AJAX request to the proper URL.
For your second question regarding your example, I’d be guessing that formnotitie is valid when the form is submitted, because that’s where it gets redirected to “home”.
As a couple of general comments on your coding style that you haven’t asked for…
You don’t need to combine “filter” with “all”.
Gegevensdrager.objects.filter(id=id_gegevensdrager)
is perfectly valid.
But even better is:
Gegevensdrager.objects.get(id=id_gegevensdrager)
which returns one object and not a queryset.
Or, if you want some “guards” around the possibility that someone could issue a POST with an invalid value for either id_zaak or id_gegevensdrager:
get_object_or_404(Zaak, id=id_zaak)
Ken