views:

109

answers:

1

Hi,

I was wondering if I could eliminate django session calls for specific views. For example, if I have a password reset form I don't want a call to the DB to check for a session or not. Thanks!

+1  A: 

Sessions are lazily loaded: if you don't use the session during a request, Django won't load it.

This includes request.user: if you access it, it accesses the session to find the user. (It loads lazily, too--if you don't access request.user, it won't access the session, either.)

So, figure out what's accessing the session and eliminate it--and if you can't, at least you'll know why the session is being pulled in.

Glenn Maynard
Do you know of a way to check for session calls without using something like django-logging? That's what I'm using for checking sql calls right now and I don't know if the session call is for django-logging or for the actual app. I eliminated the session call but it still seems to be querying.
xtrahotsauce
If you don't mind temporary hacking Django source (which I generally find inevitable), edit django.contrib.sessions.backends.base.SessionBase._get_session and make it dump a backtrace when it calls load(). That'll quickly tell you who's triggering session loads.
Glenn Maynard