How to set and get session variable in django?
For setting session variable: request.session[‘idempresa’] = profile.idempresa For getting session Data: if ‘idempresa’ in request.session: idempresa = request.session[‘idempresa’]
For setting session variable: request.session[‘idempresa’] = profile.idempresa For getting session Data: if ‘idempresa’ in request.session: idempresa = request.session[‘idempresa’]
There are two parameters to expire sessions, SESSION_EXPIRE_AT_BROWSER_CLOSE and SESSION_COOKIE_AGE. If you want to expire in 5 minutes yours settings should like as: SESSION_EXPIRE_AT_BROWSER_CLOSE = False SESSION_COOKIE_AGE = 5 * 60 To combine both learn how do it writing your custom middleware “Is there a way to combine behavior of SESSION_EXPIRE_AT_BROWSER_CLOSE and SESSION_COOKIE_AGE”
If you set your session cookie domain to start with a “.” character it will let you handle wildcard sub-domains and share a session cookie (login session) across multiple subdomains. In settings.py: SESSION_COOKIE_DOMAIN=”.stackoverflow.com” The above would allow a cookie to be shared across user1.stackoverflow.com and user2.stackoverflow.com. If you really do want the url’s to be … Read more