151π
β
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.
3π
In case you want the raw cookie string (tested with Django 4.1)
request.META.get('HTTP_COOKIE')
π€Arnaud P
- [Django]-Django set DateTimeField to database server's current time
- [Django]-How can I serialize a queryset from an unrelated model as a nested serializer?
- [Django]-Converting timezone-aware datetime to local time in Python
Source:stackexchange.com