def setCookie(request):
response = render(request,"index.html")
maxAge = 1 * 24 * 60 * 60
response.set_cookie("key", "value", max_age = maxAge) # max_age = 1 day
def getCookie(request):
value = request.COOKIES.get('key')
if value is None:
# Cookie is not set
def setcookie(request):
html = HttpResponse("<h1>Dataflair Django Tutorial</h1>")
html.set_cookie('dataflair', 'Hello this is your Cookies', max_age = None)
return html
# views.py
def viewdata(request):
# html file index.html
response = render(request,"index.html")
# Set Cookies
response.set_cookie('mefiz', 'mefiz.com')
# Get Cookies
value = request.COOKIES.get("mefiz")
print(value)
# Return Responce
return response