Anonymous-session support

Posted by Adrian Holovaty on August 16, 2005

By popular demand, we've added support for anonymous sessions. See the full session documentation.

Here's a 10-second example. request.session is a simple, dictionary-like object:

def post_comment(request, new_comment):
    if request.session.get('has_commented', False):
        return HttpResponse("You've already commented.")
    c = comments.Comment(comment=new_comment)
    c.save()
    request.session['has_commented'] = True
    return HttpResponse('Thanks for your comment!')

IMPORTANT: If you're using a Django installation from before revision 469, you'll have to take a few small steps to use the new session system -- and the admin system uses the session system, so chances are you'll be affected by this change. For full details, see the "Added support for anonymous sessions" section of the backwards-incompatible changes page.

Back to Top