If I have a registration with 3 steps, that will use 3 forms.
Something like this, just to demonstrate:
@app.route('/form/step1', methods=['GET', 'POST'])
def form_step1():
form = form_step_1(request.form)
...validate()...
return render_template('register.html', form=form)
@app.route('/form/step2', methods=['GET', 'POST'])
def form_step2():
form = form_step_2(request.form)
...validate()...
return render_template('register.html', form=form)
@app.route('/form/step3', methods=['GET', 'POST'])
def form_step3():
form = form_step_3(request.form)
...validate()...
return render_template('register.html', form=form)
What is the correct way to handle data between these three steps? All data should be committed to database at the end of the step 3. But a back action between the forms should populate again the previous form.
Use sessions for this purpose seems bad.
If you do not have any reason to worry about POST hijacking of your form data, you can use hidden form fields in the 2nd and 3rd view to pass data along. Think along these lines...
Now, when your form goes to POST in step 3, if valid, each form's data from the previous steps are available.
If you want a foolhardy solution (that requires a bit more work), look into Django FormWizard
I would personally suggest using the session object to pass data from one form to another. If you have a small amount of data then you can get away with just using the cookie implementation that flask has. Otherwise, you can override the default sessions object to store sessions data server side using Redis. This lets you use session objects without paying the price of storing lots of data in cookies. This means you can do something like