Im trying to logout of my lockdown session. In the docs it says
LOCKDOWN_LOGOUT_KEY
A key which, if provided in the query string of a locked URL, will log out the user from the preview.
I'm not sure if I understand it rightly. I tried to implement this like this:
- I have the lockdown middleware in the middleware list.
- I have these lockdown options in settings.py:
LOCKDOWN_FORM = 'lockdown.forms.AuthForm'
LOCKDOWN_AUTHFORM_STAFF_ONLY = False
LOCKDOWN_LOGOUT_KEY = 'logout'
- I have a button which links to "/logout/"
<form action="/logout/">
<input type="submit" value="Logout"/>
</form>
- This just links to a HttpResponseRedirect() back to my main page:
urls.py:
path('logout/', views.logout, name='logout')
views.py:
def logout(request):
return HttpResponseRedirect("/")
The link works and takes me back to my main page. But the logout doesn't occure. Does anyone know how to do this?
EDIT: I found a solution. I added one line of code to the logout function in views.py:
def logout(request):
request.session.flush()
return HttpResponseRedirect("/")
I found a solution. I added one line of code to the logout function in views.py: