Cookies not showing up in environ

abc abc useracct222 at gmail.com
Fri Jul 20 15:39:38 EDT 2018


I am trying the simplest of examples below to set and read a cookie. I am using the Django framework, but I have also tried with vanilla python cookies and os.environ. I have posted elsewhere, but this hasn't gotten much attention, so I'd really appreciate any help.

Thinking at this point it may be something to with the server, not python. I have tried uwsgi/nginx, gunicorn/nginx, django development server with no success.

view.py:

def index(environ, start_response, request):
    if not 'HTTP_COOKIE' in environ:
        response = HttpResponse("hello")
        response.set_cookie('user_agreement', 'cookie text', domain='.mysite.com')
        return response
    else:
        print environ['HTTP_COOKIE']

The webpage just prints 'hello' and never reaches the else not matter how many times I refresh the page. There are no cookies in the browser ever either.

Am I missing some middleware? I remember some answers to cookie problems related to the order of their middleware configurations. Here's mine:

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]


More information about the Python-list mailing list