On donderdag 19 juli 2018 10:34:35 CEST need_some_help wrote:

> I first need to make sure I am accessing them correctly. This is as simple
> as it gets I imagine:
> 
> 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?

No, you have the wrong assumption about a view method's signature. The first 
argument 
is always the request, as in django.http.HttpRequest or more specifically, it's 
subclass 
django.core.handlers.WSGIRequest in the case of WSGI.
You're not writing a WSGI handler (who has environ as first argument). A view 
is two stops 
down and to give you the complete onion:
WSGI Handler -> Middleware -> view -> Middleware -> WSGI Handler

Anyway, the cookies are at request.COOKIES as per docs[1].
-- 
Melvyn Sopacua

--------
[1] https://docs.djangoproject.com/en/2.0/ref/request-response/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2658575.uAxzzMfALO%40fritzbook.
For more options, visit https://groups.google.com/d/optout.

Reply via email to