D
D
DmitryRise2017-05-09 16:06:43
Django
DmitryRise, 2017-05-09 16:06:43

How to properly use sessions in Django?

I'm trying to use sessions to work with variables in different methods (Views)
Method 1

if form.is_valid():
            countries = form.cleaned_data.get('countries')
            request.session['countries'] = countries

Method 2 And I get at the same time
countries = request.session['countries']

Exception Type: KeyError
Exception Value: 'countries'

Session settings are set. Something I'm doing wrong

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maxfox, 2017-05-09
@maxfox

Pavel Denisov +1
Most likely, you do not write to the session, because the form did not pass the validation. Well, or something else.
This part of the documentation is required to study before all the rest: https://docs.djangoproject.com/en/1.11/topics/logging/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question