[Answered ]-Why I can not get cookies from requests.get

2👍

✅

You have to:

  1. Set the cookie into the Response object

    response = render(request, 'command.html', {'result': request.META.items()})
    response.set_cookie('cookie_name', 'cookie_value')
    return response
    
  2. Search for the cookie inside request.COOKIES

    if 'cookie_name' in request.COOKIES:
        cookie_value = request.COOKIES['cookie_name']
    

0👍

requests.get(r'http://127.0.0.1:8000/info/').cookies.items())

This looks ok to me. If it returns an empty list, it means that your view is not setting any cookies.

By default, Django only sets the session cookie when the session has been modified. See the Django docs on when sessions are saved for more information.

Leave a comment