📜  如何在 django 中访问 cookie - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:38.793000             🧑  作者: Mango

代码示例2
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.