1
votes

I have a multi-page form in Django. That is to say I have multiple Django Form objects spread across five or so templates. What I would like to do is pass that form between the pages, then commit it to my model at the end of the string. My code snippet is as follows:

def firstFormStep(request):
    if form.is_valid() :
        for field in form :
            request.session[str(field.name)] = form.cleaned_data[str(field.name)]
        request.session.modified = True
        request.session.save()
        print ("Request: " + str(request.session.items()))
        print ("Session: " + str(request.session.session_key))
        return HttpResponseRedirect(reverse('core:nextFormStep'), request)

Before session.save() my session_key was None. Afterwards it is a number.

The first line of my next view is:

def nextFormStep(request):
    print ("Session: " + str(request.session.session_key))

The session_key at this point is None. Somewhere in HttpResponseRedirect my session gets dropped. Why? How can I fix this?

1
show your settings files with SESSION settings.Usman Maqbool

1 Answers

0
votes

Thanks to Usman Maqbool I found that my error was that SESSION_COOKIE_SECURE was set to True in my dev environment.