I've followed numerous examples, but the only one that does not return 
errors are the implementations of the two functions below. There doesn't 
seem to be an HTTP_COOKIE key in the environ. The request value only gets 
set with POST and GET. Think something is wrong with my setup, because none 
of the common usage patterns I've seen online like request.POST don't work. 
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:

view.py

def index(environ, start_response, request):
    print request
    print environ.keys()
    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


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')])
    # DO I NEED AT SET COOKIE HEADER HERE?
    return view.index(environ, start_response, request)

OUTPUT:

request: {}

environ.keys():
['RUN_MAIN', 'HTTP_REFERER', 'XDG_GREETER_DATA_DIR', 'QT4_IM_MODULE', 
'SERVER_SOFTWARE', 'UPSTART_EVENTS', 'SCRIPT_NAME', 'XDG_SESSION_TYPE', 
'REQUEST_METHOD', 'CONTENT_LENGTH', 'SERVER_PROTOCOL', 'HOME', 'DISPLAY', 
'LANG', 'SHELL', 'PATH_INFO', 'XDG_DATA_DIRS', 
'QT_LINUX_ACCESSIBILITY_ALWAYS_ON', 'MANDATORY_PATH', 
'COMPIZ_CONFIG_PROFILE', 'UPSTART_INSTANCE', 'JOB', 'SESSION', 
'LIBGL_ALWAYS_SOFTWARE', 'SERVER_PORT', 'CLUTTER_IM_MODULE', 'XMODIFIERS', 
'GTK2_MODULES', 'HTTP_PRAGMA', 'XDG_RUNTIME_DIR', 'COMPIZ_BIN_PATH', 
'VTE_VERSION', 'HTTP_CACHE_CONTROL', 'HTTP_CONNECTION', 'HTTP_HOST', 
'wsgi.version', 'XDG_CURRENT_DESKTOP', 'XDG_SESSION_ID', 
'DBUS_SESSION_BUS_ADDRESS', 'GNOME_KEYRING_PID', 'HTTP_ACCEPT', 
'DESKTOP_SESSION', 'LESSCLOSE', 'DEFAULTS_PATH', 'wsgi.run_once', 
'wsgi.errors', 'wsgi.multiprocess', 'HTTP_ACCEPT_LANGUAGE', 'INSTANCE', 
'LS_COLORS', 'XDG_SEAT', 'GNOME_DESKTOP_SESSION_ID', 'LESSOPEN', 
'QUERY_STRING', 'QT_IM_MODULE', 'LOGNAME', 'USER', 'GNOME_KEYRING_CONTROL', 
'XDG_VTNR', 'PATH', 'TERM', 'HTTP_USER_AGENT', 'XDG_SESSION_PATH', 
'XAUTHORITY', 'LANGUAGE', 'REMOTE_ADDR', 'SHLVL', 'QT_QPA_PLATFORMTHEME', 
'wsgi.url_scheme', 'QT_ACCESSIBILITY', 'WINDOWID', 'SESSIONTYPE', 
'IM_CONFIG_PHASE', 'GPG_AGENT_INFO', 'XDG_SESSION_DESKTOP', 
'SSH_AUTH_SOCK', 'GDMSESSION', 'UPSTART_JOB', 'wsgi.multithread', 
'XDG_SEAT_PATH', 'TZ', '_', 'wsgi.input', 'GTK_IM_MODULE', 
'UPSTART_SESSION', 'XDG_CONFIG_DIRS', 'SERVER_NAME', 'GATEWAY_INTERFACE', 
'OLDPWD', 'GDM_LANG', 'GTK_MODULES', 'PWD', 'DJANGO_SETTINGS_MODULE', 
'CONTENT_TYPE', 'wsgi.file_wrapper', 'REMOTE_HOST', 'HTTP_ACCEPT_ENCODING']

You can see their is no HTTP_COOKIE in the keys. If I'm not setting it 
right, or there's something I need to check, please let me know.

-- 
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/efca47a4-1a14-426a-88ce-5a9c20474046%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to