You can read cookies from the request via the request.COOKIES dictionary. See the documentation here: https://docs.djangoproject.com/en/2.0/ref/request-response/#django.http.HttpRequest.COOKIES
You won't find them in an environment variable, which is shared process-wide and across all requests, because they are bound to each request. This is not a CGI script, so those HTTP_* environment variables you seem to expect won't be here. On Fri, Jul 20, 2018 at 3:39 PM, abc abc <[email protected]> wrote: > 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', > ] > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
