How to clear cookies with Django

I am trying to create a login page for a website. I am using Django 1.4.2. I saved users who entered the cookie correctly using set_cookie . But I did not find clear_cookie in the Django documentation. How to clear the cookie so that the user logs out?

+7
source share
2 answers

Cookie Settings:

  def login(request): response = HttpResponseRedirect('/url/to_your_home_page') response.set_cookie('cookie_name1', 'cookie_name1_value') response.set_cookie('cookie_name2', 'cookie_name2_value') return response 

Deleting cookies:

  def logout(request): response = HttpResponseRedirect('/url/to_your_login') response.delete_cookie('cookie_name1') response.delete_cookie('cookie_name2') return response 
+19
source

You can simply delete everything that you saved in the cookie - this way, although the cookie exists, it no longer contains any information needed to track the session, and the user must log in again.

(Also, it looks like a duplicate of exit to Django (redirecting to the main page). Delete cookie? )

-one
source

All Articles