Shahid Har
Shahid Har
• Django provide built in method to set and get cookies. The set cookie is used to set a cookie and
get cookie is used to get a cookie.
• Cookie has its expiry date and removes automatically when gets expired.
Getting and Setting Cookies
• Reading cookies that are already set is incredibly simple. Every request object has a COOKIES
object that acts like a dictionary; we can use it to read any cookies that the browser has sent to the
view:
• def show_color(request):
if "favorite_color" in request.COOKIES:
request.COOKIES["favorite_color"]) else:
• def login(request):
request.method == 'POST’:
if request.session.test_cookie_worked():
request.session.delete_test_cookie()
THANK YOU