Below is my code.
def sessfun(request) :
num_visits = request.session.get('num_visits', 0) 1
request.session['num_visits'] = num_visits
if num_visits > 4 : del(request.session['num_visits'])
resp = HttpResponse('view count=' str(num_visits))
return resp
The code use request.session. It works well. When I visit in chrome and Firefox, it makes another session.
But my question is session is saved in server, but how can request get session??
And How session distinguish user without any session id or something...
CodePudding user response:
By default django will include the identifier in a session cookie. This is sent along with every request. Based on this identifier, django then pulls out the corresponding user from the db.