Test if sessions are working

 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

  1. Cookieless Session Middleware by juliocarlos 3 years, 2 months ago
  2. Persistent Session Debugging with Django Debug Toolbar by brianjaystanley 3 months, 3 weeks ago
  3. Upload, Progressbar with sessions by revolunet 3 years, 5 months ago
  4. Clean up expired django.contrib.session's in a huge MySQL InnoDB table by patsplat 3 years, 1 month ago
  5. Mobilize your Django site by stevena0 2 years, 10 months ago

Comments

(Forgotten your password?)