简体   繁体   English

如何在 Django 视图中添加对 cookie 的访问

[英]How add access to cookie in Django views

Hello friends i am beginner and i have a code that i added it below.你好朋友我是初学者,我有一个我在下面添加的代码。

i have view that uses as refresh_token.我有用作 refresh_token 的视图。 my boss tell to me adde access to cookie but i do not know how to add it?where to add it?我的老板告诉我添加对 cookie 的访问,但我不知道如何添加它?在哪里添加它? can anyone give me a solution or send me a link about it?谁能给我一个解决方案或给我一个链接? if have less knowledge about cookie and and complete request structure if can me a link for describe that i am thankful.如果对 cookie 和完整的请求结构知之甚少,如果我能提供一个描述链接,我很感激。 enter image description here在此处输入图像描述

You can set the token in cookies like this:您可以像这样在 cookies 中设置令牌:

def your_view(request):
    response = HttpResponse()
    response.set_cookie('access_token', your_access_token, httpOnly=True)
    response.set_cookie('refresh_token', your_refresh_token, httpOnly=True)
    return response

and you can get it with request.COOKIES['access_token']你可以用request.COOKIES['access_token']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM