cookies in django
def setcookie(request):
html = HttpResponse("<h1>Dataflair Django Tutorial</h1>")
html.set_cookie('dataflair', 'Hello this is your Cookies', max_age = None)
return html
cookies in django
def setcookie(request):
html = HttpResponse("<h1>Dataflair Django Tutorial</h1>")
html.set_cookie('dataflair', 'Hello this is your Cookies', max_age = None)
return html
how to access cookies in django
You can't just start calling methods on the HttpResponse class, you have to instantiate it e.g. response = HttpResponse("Hello World"), call the cookie method, and then return it from your view.
response = render_to_response(template_name, context)
response.set_cookie('logged_in_status', 'never_use_this_ever')
return response
# remember my other answer:
# it's a terrrible idea to set logged in status on a cookie.
To get the cookie:
request.COOKIES.get('logged_in_status')
# remember, this is a terrible idea.
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us