Day21-获取用户请求相关信息及请求头

1. request里面还包含请求头等信息,可以打印看一下。

views.py中的程序

from django.shortcuts import render,HttpResponse
from django.urls import reverse
# Create your views here.
def test(request):
    print(type(request))
    #print(request.environ)#字典格式
    #封装了所有用户请求信息
    for k,v in request.environ.items():
        print(k,v)
    return HttpResponse('OK')

  

打印出来的结果

<class 'django.core.handlers.wsgi.WSGIRequest'>
ADAPTIVACLIENT "C:\Program Files (x86)\Adaptiva\AdaptivaClient"
ALLUSERSPROFILE C:\ProgramData
APPDATA C:\Users\ECHNDOA\AppData\Roaming
COMMONPROGRAMFILES C:\Program Files (x86)\Common Files
COMMONPROGRAMFILES(X86) C:\Program Files (x86)\Common Files
COMMONPROGRAMW6432 C:\Program Files\Common Files
COMPUTERNAME CN00121475
COMSPEC C:\WINDOWS\system32\cmd.exe
DADIR C:\Program Files (x86)\CheckPoint\Endpoint Security\Endpoint Common
ERLANG_HOME C:\abccdxddd\Oldboy\Erlang\erl9.0
FP_NO_HOST_CHECK NO
HOMEDRIVE C:
HOMEPATH \Users\ECHNDOA
LIB C:\Program Files (x86)\sql11\LIB
LNKENV C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE
LOCALAPPDATA C:\Users\ECHNDOA\AppData\Local
LOGONSERVER \\SGSKIWEGAD00001
MOZ_PLUGIN_PATH C:\Program Files (x86)\Foxit Software\Foxit Reader\plugins\
NUMBER_OF_PROCESSORS 4
OS Windows_NT
PATH C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files (x86)\SQL11\DLL;C:\Program Files (x86)\SQL11\BIN;C:\Program Files (x86)\CheckPoint\Endpoint Security\Endpoint Common\bin;C:\abccdxddd\Oldboy\python-3.5.2-embed-amd64;C:\abccdxddd\Oldboy\python-3.5.2-embed-amd64\Scripts;C:\abccdxddd\Oldboy\mysql\mysql-5.7.19-winx64\bin;C:\abccdxddd\Oldboy\Scripts
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE x86
PROCESSOR_ARCHITEW6432 AMD64
PROCESSOR_IDENTIFIER Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
PROCESSOR_LEVEL 6
PROCESSOR_REVISION 3c03
PROGRAMDATA C:\ProgramData
PROGRAMFILES C:\Program Files (x86)
PROGRAMFILES(X86) C:\Program Files (x86)
PROGRAMW6432 C:\Program Files
PSMODULEPATH C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC C:\Users\Public
PYCHARM_HOSTED 1
PYTHONIOENCODING UTF-8
PYTHONPATH C:\abccdxddd\Oldboy\Py_Exercise\Day21django
PYTHONUNBUFFERED 1
SESSIONNAME Console
SYBASE C:\Program Files (x86)\SQL11
SYSTEMDRIVE C:
SYSTEMROOT C:\WINDOWS
TEMP C:\Users\ECHNDOA\AppData\Local\Temp
TMP C:\Users\ECHNDOA\AppData\Local\Temp
UATDATA C:\WINDOWS\CCM\UATData\D9F8C395-CAB8-491d-B8AC-179A1FE1BE77
USERDNSDOMAIN ERICSSON.SE
USERDOMAIN ERICSSON
USERDOMAIN_ROAMINGPROFILE ERICSSON
USERNAME echndoa
USERPROFILE C:\Users\ECHNDOA
WINDIR C:\WINDOWS
WINDOWS_TRACING_FLAGS 3
WINDOWS_TRACING_LOGFILE C:\BVTBin\Tests\installpackage\csilogfile.log
DJANGO_SETTINGS_MODULE Day21django.settings
RUN_MAIN true
SERVER_NAME CN00121475.ericsson.se
GATEWAY_INTERFACE CGI/1.1
SERVER_PORT 8000
REMOTE_HOST 
CONTENT_LENGTH 
SCRIPT_NAME 
SERVER_PROTOCOL HTTP/1.1
SERVER_SOFTWARE WSGIServer/0.2
REQUEST_METHOD GET
PATH_INFO /test/
QUERY_STRING 
REMOTE_ADDR 127.0.0.1
CONTENT_TYPE text/plain
HTTP_HOST 127.0.0.1:8000
HTTP_CONNECTION keep-alive
HTTP_CACHE_CONTROL max-age=0
HTTP_USER_AGENT Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
HTTP_UPGRADE_INSECURE_REQUESTS 1
HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
HTTP_ACCEPT_ENCODING gzip, deflate, br
HTTP_ACCEPT_LANGUAGE zh-CN,zh;q=0.8
HTTP_COOKIE csrftoken=S0CsgtTGIL9dViRJ9fETtc1OMlQScE1qboY8Be62HyBimfLJRQoWQ7QuMHVGLlbt
wsgi.input <_io.BufferedReader name=768>
wsgi.errors <_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>
wsgi.version (1, 0)
wsgi.run_once False
wsgi.url_scheme http
wsgi.multithread True
wsgi.multiprocess False
wsgi.file_wrapper <class 'wsgiref.util.FileWrapper'>
CSRF_COOKIE S0CsgtTGIL9dViRJ9fETtc1OMlQScE1qboY8Be62HyBimfLJRQoWQ7QuMHVGLlbt

  

posted on 2017-10-13 16:18  momo8238  阅读(291)  评论(0编辑  收藏  举报