As part of the registration process for my site, I have several views that set up session data. Later views depend on the established session data. All this works fine in the browser, however, when I try to check it, the session data seems to be lost between requests, which makes testing impossible. Here is a simple example of the problem I am having. I would expect get_name to gain access to the ['name'] session and return 200, however session data would be lost and get_name would return 302.
>>> c = Client()
>>> r = c.post(reverse(set_name))
>>> r = c.post(reverse(get_name))
>>> r.status_code
200
def set_name(request):
request.session['name'] = 'name'
return HttpResponse()
def get_name(request):
try:
name = request.session['name']
except KeyError:
return redirect(reverse(set_name))
return HttpResponse(name)
source
share