request.session is not transferring full querydict to another view
Solution 1:
you cannot send all the post data
like that, as you have list inside your input names,
you have to access each names differently and set them in the session
.
request.session['question_data'] = request.POST.getlist('topics_all')
same for other input names
, then access with key in the second view
Solution 2:
The session is not saved by default. Add request.session.modified = True
:
def question_filter(request):
if request.method == 'POST':
print('before validation', request.POST)
request.session['question_data'] = request.POST
request.session.modified = True
return HttpResponseRedirect(reverse('qapp:question_preview'))
https://docs.djangoproject.com/en/2.0/topics/http/sessions/#when-sessions-are-saved
Edit:
You can hack it using json:
import json
def question_filter(request):
if request.method == 'POST':
print('before validation', request.POST)
request.session['question_data'] = json.dumps(request.POST)
return HttpResponseRedirect(reverse('qapp:question_preview'))
def question_preview(request):
all_questions = Questions.objects.all()
question_data = json.loads(request.session.get('question_data'))
print(question_data)
question_pk_list = question_data['question_pk']
preview_questions = all_questions.filter(id__in=question_pk_list)
...
return render(request,'apps/qapp/question_preview.html', {somecontext})