D
D
Dauren S2020-10-28 07:36:24
HTTP Cookies
Dauren S, 2020-10-28 07:36:24

Django set cookie?

From the front :8080 I send a request to django :8000, in the response I try to create a cookie

from rest_framework.response import Response
def post(self,request):
    response = Response({"users": serializer.data})
    response.set_cookie(key='api_token', value=12,max_age=30, domain='127.0.0.1', secure=False, httponly=True,samesite='None')

The cookie arrives, but the cookie not set notification comes out, since samesite=None and Secure must be True, if I set Secure to True, then it requires https.
Is there any way to bypass these conditions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-10-28
@dauren101

In this case, most likely the cookie should be set not by the server, but by js on the client. Well, in general, if there is api_token, then authentication on tokens is implied, and it is better to do this not based on cookies, but through the header

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question