django的view中如何设置和读取cookie的值?


django的view中,如何设置和读取cookie的值?

开发 django cookie

jde51 9 years, 11 months ago

请参考以下示例:

在view中设置cookie

response = render_to_response(template_name, context)
response.set_cookie('layout', 'card') 
return response

注意:尽量不要把登录信息设置到cookie中

读取cookie

request.COOKIES.get(‘layout')
NINI喵 answered 9 years, 11 months ago

Your Answer