Reputation: 1059
I've a 4-page form, where in 3rd form i'm selecting an image for upload. I'm storing the contents of first 3 forms in session. after 4th form is submitted, i'm collecting the required data from session variables and saving them in database. How do i destroy the session variables in django after 4th form is submitted because when i'm filling a new 4-page form, i get the previously uploaded image in 3rd form.
Is there any better way to execute multi-page forms in django?
Upvotes: 0
Views: 988
Reputation: 52028
You need to call del request.session['key']
to delete data from session. So try like this:
def fourth_form_submission(request):
form = FourthForm(request.POST)
if form.is_valid():
data = form.cleaned_data
# save data to DB from session
try:
del request.session['form_1_data']
del request.session['form_2_data']
del request.session['form_3_data']
except KeyError:
pass
return HttpResponse("Data has been saved.")
Or you can use flush()
, but it will delete all session data.
More information can be found regarding this in documentation
.
Upvotes: 1