Django Session KeyError when key exists
问题 The following code works locally when I use Django's development server, but I am running into intermittent bugs in production with Nginx and Gunicorn. views.py def first_view(request): if request.method == "POST": # not using a django form in the template, so need to parse the request POST # create a dictionary with only strings as values new_post = {key:val for key,val in request.POST.items() if key != 'csrfmiddlewaretoken'} request.session['new_post'] = new_mappings # save for use within