Django: use render_to_response and set cookie

前端 未结 1 1758
Happy的楠姐
Happy的楠姐 2021-01-02 03:32

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

1条回答
  •  醉话见心
    2021-01-02 04:24

    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 讨论(0)
提交回复
热议问题