You can't do:
wsgi.py:
def application(environ, start_response):
try:
request_body_size = int(environ.get('CONTENT_LENGTH', 0))
except (ValueError):
request_body_size = 0
request_body = environ['wsgi.input'].read(request_body_size)
request = parse_qs(request_body)
start_response('200 OK', [('Content-Type', 'text/html')])
return omicron.view.index(environ, start_response, request)
The second argument to start_response() needs to be the response headers. It is
those response headers which is where the cookie information is passed back to
the browser. It is not included in the response content.
You would have to work out how to get the response headers from the Django
HTTPResponse object and combine them with, or use them as the second argument
to start_response().
The following may work, but the Django HTTPResponse object is not meant to be
used like that with raw WSGI.
response = omicron.view.index(environ, start_response, request)
start_response('200 OK', response._headers)
return response
None of the links you have been including show anyone using a Django
HTTPResponse object with raw WSGI like you are trying with this example. They
are only using it within the context of a complete Django application.
The only thing I don't understand is why you are trying to use HTTPResponse
with raw WSGI. As a test of why cookies aren't working, it is the wrong way of
going about it. You need to have a full Django application project structure
and use its way of doing things.
Didn't you start out with:
django-admin.py startproject yourprojectname
What happened to your Django project structure?
Graham
> On 10 Jul 2018, at 8:02 pm, at_your_mercy <[email protected]> wrote:
>
> You misunderstand, I'm not "trying to do" anything in particular except make
> things work. I thought I was using the django framework to set the cookies,
> but can't read them. Right now I'm trying to determine if I'm not setting
> them or reading them correctly. According to the following:
>
> https://stackoverflow.com/questions/1622793/django-cookies-how-can-i-set-them
>
> https://www.tutorialspoint.com/django/django_cookies_handling.htm
>
> https://overiq.com/django/1.10/cookies-in-django/
>
> I should be using response.set_cookie() which is what I have:
>
> template = loader.get_template('index-test.html')
> response = HttpResponse(template.render(None))
> response.set_cookie('name1', 'test-cookie')
> response.set_cookie('name2', 'test-cookie')
> return response
>
> If it matters, I do plan to eventually move from the Django development
> server to Apache or NGINX. Otherwise, if this is not a wsgi problem, please
> let me know so I can focus my attention elsewhere. Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "modwsgi" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/modwsgi
> <https://groups.google.com/group/modwsgi>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.