Reputation: 41
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:
LOCKDOWN_FORM = 'lockdown.forms.AuthForm'
LOCKDOWN_AUTHFORM_STAFF_ONLY = False
LOCKDOWN_LOGOUT_KEY = 'logout'
<form action="/logout/">
<input type="submit" value="Logout"/>
</form>
urls.py:
path('logout/', views.logout, name='logout')
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("/")
Upvotes: 0
Views: 190
Reputation: 6162
Just add the value of LOCKDOWN_LOGOUT_KEY
("preview-logout" by default) as a query string parameter.
<a href="/?preview-logout">Log out</a>
Upvotes: 0
Reputation: 41
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("/")
Upvotes: 0