I want to create a cookie to save certain data when the user starts session. I read the cookies that exist with request.COOKIES['cookie_name']
but I am not able to create one.
Thank you very much!
I want to create a cookie to save certain data when the user starts session. I read the cookies that exist with request.COOKIES['cookie_name']
but I am not able to create one.
Thank you very much!
According to the Django documentation
what you must do to send a cookie in the answer is precisely, take the answer, and help you from the method set_cookie
, which has the following parameters key, value='', max_age=None, expires=None, path='/', domain=None, secure=None, httponly=False
and you must use it in the following way:
# cuando estes enviando tu respuesta
...
response = HttpResponse(content_type='text/html')
response.set_cookie('llave', 'valor')
And you recover it as you already know how to do it.