I have to assume that the problem is global. The session data is only used for a presentation view and a view which serves a text file (for user to download), the latter is only reachable by the user after the former.
from views.py:
def index(request):
context = {}
#### sends form to new visitors
if request.method == 'GET':
# the numbers from which multiples can be chosen
context["quantity"] = quantity
context["operators"] = opChoices
context["limits"] = limits
context["multChoices"] = multChoices
return render(request, 'generator/form.html', context)
### reading submitted form data for parameters
params = {
'quantity': request.POST['quantity'],
'operators': getOps(request.POST),
'attributes': getAttr(request.POST),
'number0': numberSymbol(int(request.POST['leftRange-lower']),
int(request.POST['leftRange-upper']),
getMults(request.POST)[0]),
'number1': numberSymbol(int(request.POST['rightRange-lower']),
int(request.POST['rightRange-upper']),
getMults(request.POST)[1])
}
### generate questions based on collected information
generated_qna = generateQuestions(params)
# line by line data
printed_qna = generatePresentation(generated_qna)
context["params"] = params
request.session["questions"] = printed_qna['questions']
request.session["answers"] = printed_qna['answers']
context["questions"] = request.session["questions"]
context["answers"] = request.session["answers"]
# clean operator symbols for human reading
context["humanOperators"] = (human_list(human_clean(params["operators"])))
return render(request, 'generator/generated.html', context)
def download(request):
context = {}
#### prevents accessing the wrong page
if request.method == 'GET':
# force 404
return HttpResponse("such hack, very disappoint, wow")
### download text files
content = (docText["title"] + "\n"
+ docText["slogan"] +"\n\nQuestions only\n"
+ ''.join(request.session["questions"])
+ "\n"
+ "Questions with Answers\n"
+ ''.join(request.session["answers"]))
response = HttpResponse(content_type='text/plain; charset=utf8')
response['Content-Disposition'] = 'attachment; filename="%s.txt"' % "MathMaker"
response.write(content)
return response
locally I was using python 3.5 no virtualenv.