Search code examples
djangodjango-sessions

Accessing session expiry date in Django template


I'm setting the session value for a variable in my as follows

request.session['a'] = True
request.session.set_expiry(604800)

If I access the session in my template as follows, it shows it's value

{{ request.session.a }}

How can I get the session expiry date for this in my template?

I tried {{ request.session.a.get_expiry_date }} and {{ request.session.a.expire_date }} but both did not work.


Solution

  • {{ request.session.get_expiry_date }} in a template gives the session expiry date.

    I also learned that

    request.session['a'] = True
    request.session.set_expiry(604800)
    

    sets the expiry for the entire session and not just that key.