1

I am using FormView to get some input from the user. I then try to set some of that data into the session to be used after the form validates and the user is redirected. The data is however lost.

The view:

    class SomeFormView(FormView):
        template_name = 'something.html'
        form_class = SomeForm

        def form_valid(self, form):
            self.request.session['some_key'] = 'some value'

            # According to manual, this should work
            self.request.session.modified = True

            # Hail Mary
            self.request.session.save()

            return super().form_valid(form)

If I look at the self.request.session contents prior to the redirect, it will have the value I've set as: '_session_cache': {'some_key': 'some_value'}

But when I arrive at the redirect, the data is nowhere to be found. I tested this on Django 3.1.1 and Django 2.2.16, with both acting the same

T-101
  • 209
  • 2
  • 13

0 Answers0