I wasn't sure if my setup supported sessions properly. This view helped me make sure.
Usage: fill the inputs with text and make sure that these values traverse a couple of requests. If it doesn't work then maybe the session backend you've set is broken?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | from django import http
def test(request):
response = 'POST:<table>'
for k,v in request.POST.items():
response += '<tr><td>%s</td><td>%s</td></tr>' % (k, v)
response += '</table>'
response += 'Session:<table>'
for k,v in request.session._session.items():
response += '<tr><td>%s</td><td>%s</td></tr>' % (k, v)
response += '</table>'
response += '''
<form method="post" action="">
<input type="text" name="new_key" />
<input type="text" name="new_value" />
<input type="submit" />
</form>
'''
new_key = request.POST.get('new_key', False)
new_value = request.POST.get('new_value', False)
if new_key and new_value:
request.session[new_key] = new_value
return http.HttpResponse(response)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 8 months ago
Comments
Please login first before commenting.