Answer a question

I redirect the user to the home page after logout. In between I would like to delete all/or specific client cookies (I have previously set).

def logoutuser(request):
    logout(request)
    return redirect('app.home.views.home')

To call response.delete_cookie('user_location'), there is no response object. How do I do this?

Answers

Like jobscry said, logout() cleans session data, but it looks like you have set your own cookies too.

You could wrap auth logout view, which will return a HttpResponse:

def logout_user(request):
     response = logout(request, next_page=reverse('app.home.views.home'))
     response.delete_cookie('user_location')
     return response

Or if you're just using the logout method as opposed to the view, you can use the return value for the redirect() method you have (which I assume returns a HttpResponse too).

def logout_user(request):
     logout(request)
     response = redirect('app.home.views.home')
     response.delete_cookie('user_location')
     return response
Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐