开发者

Django: use render_to_response and set cookie

开发者 https://www.devze.com 2023-02-10 08:08 出处:网络
Currently, I\'m using render_to_response(template_name, locals(), context-etc..) Trying to set a cookie right now and I\'m wondering if I can do it with render_to_response.

Currently, I'm using render_to_response(template_name, locals(), context-etc..)

Trying to set a cookie right now and I'm wondering if I can do it with render_to_response.

All the examples I see开发者_开发问答 are using HttpResponse object. They set the cookie in the response object, like this

response = HttpResponseObject(html)
response.set_cookie("favorite_color",request.GET["favorite_color"])
return response

Wondering if I can set cookie with render_to_response, so I can continue using locals()

Thank you. David.


Yes, not a problem. The principle is exactly the same.

response = render_to_response(template_name, locals(), context-etc..)
response.set_cookie("favorite_color",request.GET["favorite_color"])
return response
0

精彩评论

暂无评论...
验证码 换一张
取 消