How can I create a Cookie in Django

0

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!

    
asked by David 11.09.2017 в 23:33
source

1 answer

0

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.

    
answered by 11.09.2017 / 23:42
source