Django logout(redirect to home page) .. Delete cookie?

后端 未结 3 834
死守一世寂寞
死守一世寂寞 2020-12-25 13:56

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(r         


        
3条回答
  •  长情又很酷
    2020-12-25 14:38

    Hope this helps: delete cookie when caling "/clear-cookies"

    location.href = '/clear-cookies';
    

    1. Define a method in views.py:

    def clear_cookies(request):
    response = HttpResponseRedirect('/')
    response.delete_cookie('_gat', domain='example.com')
    response.delete_cookie('_ga', domain='example.com')
    response.delete_cookie('_gid', domain='example.com')
    return response
    
    1. Add the path and method to your urls.py

      url(r'^clear-cookies', clear_cookies),

提交回复
热议问题