Creating an anonymous django session -


in attempts learn django, i've been trying make clone of dayscore.net. meaning that, want make site using django, not refer git clone or hg clone if take look, every time new user comes dayscore, unique session, special hash code. how achieve using django?

1) pointed in comment question django applies session id request if have enabled session middleware.

2) in case still want generate session id can create middleware on process_request you'll create hash value , add sessions.

middleware.py

import uuid  class anonhashmiddleware(object):      def process_request(self, request):         """         if user not authenticated (anonymous) set session hashcode         uuid4 hex         """         if not request.user.is_authenticated() , \                 'hashcode' not in request.session:             request.session['hashcode'] = uuid.uuid4().hex 

pros

  • no matter page of site user comes in if anonymous without hashcode he'll hashcode generated him.

cons

  • middleware applied each request coming server other middlewares.

Comments