hand
_1_35_5
4
python3.X - Web - Django3.2.9
共43篇
python3.X - Web - Django3.2.9
返回栏目
0k
0.6k
0.1k
0.2k
0.1k
0.2k
6k
1k
6k
2k
2k
0.4k
0.3k
0.3k
1k
0.5k
3k
2k
0.6k
0.9k
1k
1k
3k
0.1k
0.3k
0.4k
0.4k
0.1k
0.3k
2k
1k
1k
1k
5k
1k
1k
0k
3k
2k
0k
0.1k
0.3k
0k
返回python3.X - Web - Django3.2.9栏目
作者:
贺及楼
成为作者
更新日期:2024-03-16 11:14:01
属性介绍
request.META
request.scheme
request.path
request.encoding
request.session
request.COOKIES
request.method
获取数据的方法
request.body
request.data
name = request.GET.get("name")
name = request.POST.get("name")
request.FILES.get('pic')
FILES 只有在请求的方法为POST 且提交的<form> 带有enctype="multipart/form-data" 的情况下才会包含数据。否则,FILES 将为一个空的类似于字典的对象
def ttttt(request):
# 获取上传文件的处理对象
try:
pic = request.FILES.get('pic')
method = request.method
print(method) # POST GET
body = request.body
print(body)
path = request.path # http://127.0.0.1:8000/cockpit/ttttt/?AA=aa&BB=bb
print(path) # /cockpit/ttttt/
full_path = request.get_full_path()
print(full_path) # /cockpit/ttttt/?AA=aa&BB=bb
ajax = request.is_ajax() # 判断是不是ajax发送的请求
print(ajax) # False
cookies = request.COOKIES
print(cookies) # {'cookie1': '11', 'cookie2': '22'}
cookie1 = request.COOKIES.get("cookie1")
print(cookie1) # '11'
meta = request.META
# print(meta) # 好多好多参数,看下方
get = request.GET
print(get) # <QueryDict: {'AA': ['aa'], 'BB': ['bb']}>
AA = request.GET.get("AA", None) # http://127.0.0.1:8000/cockpit/ttttt/?AA=aa&BB=bb 不管get请求还是post请求都可以拿到
print(AA) # aa
CC = request.POST.get("aas", None)
print(CC) # cc
return JsonResponse({"code": 20000, 'message': '删除成功'})
except Exception as e:
return JsonResponse({"code": 20001, 'error': str(e)})
# {
# "ALLUSERSPROFILE": "C:\\ProgramData",
# "APPDATA": "C:\\Users\\admin123\\AppData\\Roaming",
# "BKAPP_MULTIPROCESSING": "false",
# "CHROME_CRASHPAD_PIPE_NAME": "\\\\.\\pipe\\crashpad_8836_WGDPSHPFXZAWCXBB",
# "COMMONPROGRAMFILES": "C:\\Program Files\\Common Files",
# "COMMONPROGRAMFILES(X86)": "C:\\Program Files (x86)\\Common Files",
# "COMMONPROGRAMW6432": "C:\\Program Files\\Common Files",
# "COMPUTERNAME": "DESKTOP-ES61745",
# "COMSPEC": "C:\\windows\\system32\\cmd.exe",
# "DRIVERDATA": "C:\\Windows\\System32\\Drivers\\DriverData",
# "ERLANG_HOME": "C:\\Program Files\\Erlang OTP",
# "FPS_BROWSER_APP_PROFILE_STRING": "Internet Explorer",
# "FPS_BROWSER_USER_PROFILE_STRING": "Default",
# "HOMEDRIVE": "C:",
# "HOMEPATH": "\\Users\\admin123",
# "IGCCSVC_DB": "AQAAANCMndERjHoAwE/Cl+sBAAAA0GpR0b7Jy0yURbPMJgTTcgQAAAAAAAAQZgAAAAEAAAAADXXtj5NyqQ0Sqv9XjEJgwY6xRRCiM34kLOZzBNN3m6GQAAAAAOgAAAAAIAACAAAACz24uPAbKhh6nhFJKaAu+mlCPnCyTJLReqNN+RCszDlAwmaucg9Mjqpcn6TKFwLZZeqiDZrcACnTI3013TPuCknY2L0G3h5/8CrByOvKhMTjyX0/QpuNuh1VHGD/+9AAAAAqBcM0pH/G96h7mliya9bDed6OYaZYkkuyu3WGT1mIrfVtB8JzYYcJ8xHYzkAvuzbQ2KWXyOChFvwCyrEyeTVJA==",
# "JAVA_HOME": "C:\\Program Files (x86)\\AdoptOpenJDK",
# "LOCALAPPDATA": "C:\\Users\\admin123\\AppData\\Local",
# "LOGONSERVER": "\\\\DESKTOP-ES61745",
# "MVN_HOME": "C:\\Users\\admin123\\Desktop\\tjhb\\mvn\\apache-maven-3.8.5\\bin",
# "NUMBER_OF_PROCESSORS": "8",
# "NVM_HOME": "C:\\Users\\admin123\\AppData\\Roaming\\nvm",
# "NVM_SYMLINK": "C:\\Program Files\\nodejs",
# "ONEDRIVE": "C:\\Users\\admin123\\OneDrive",
# "ONEDRIVECONSUMER": "C:\\Users\\admin123\\OneDrive",
# "ONLINESERVICES": "Online Services",
# "ORIGINAL_XDG_CURRENT_DESKTOP": "undefined",
# "OS": "Windows_NT",
# "PATH": "C:\\Users\\admin123\\Desktop\\tjhb\\huabao_screen\\huabao-screen-server\\venv\\Scripts;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Python27\\;C:\\Python27\\Scripts\\;C:\\Program Files (x86)\\AdoptOpenJDK\\jdk-8.0.292.10-openj9\\bin;C:\\windows\\system32;C:\\windows;C:\\windows\\System32\\Wbem;C:\\windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\Bandizip\\;C:\\Program Files\\TortoiseSVN\\bin;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files (x86)\\AdoptOpenJDK\\bin;C:\\Program Files (x86)\\AdoptOpenJDK\\jre\\bin;C:\\Program Files (x86)\\PuTTY\\;C:\\Program Files\\Git\\cmd;C:\\Users\\admin123\\AppData\\Roaming\\nvm;C:\\Program Files\\nodejs;C:\\Program Files\\AsiaInfo Security\\AisEsmAgent;C:\\Program Files\\Redis\\;C:\\Program Files\\Erlang OTP\\bin;C:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.12.12\\sbin;C:\\Python36\\Scripts\\;C:\\Python36\\;C:\\Users\\admin123\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\admin123\\Desktop\\tjhb\\mvn\\apache-maven-3.8.5\\bin;C:\\Users\\admin123\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Python27\\;C:\\Program Files\\mysql-5.7.38-winx64\\mysql-5.7.38-winx64\\bin;C:\\Python27\\Scripts\\;C:\\Users\\admin123\\AppData\\Roaming\\nvm\\v16.13.0;C:\\Users\\admin123\\AppData\\Roaming\\nvm;C:\\Program Files\\nodejs;C:\\Users\\admin123\\AppData\\Local\\Programs\\Python\\Python310\\;C:\\Users\\admin123\\AppData\\Local\\Programs\\Python\\Python310\\Scripts\\;C:\\Program Files\\MongoDB\\Server\\6.0\\bin;C:\\Program Files\\mysql-5.7.38-winx64\\mysql-5.7.38-winx64\\include;",
# "PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL",
# "PLATFORMCODE": "AN",
# "PROCESSOR_ARCHITECTURE": "AMD64",
# "PROCESSOR_IDENTIFIER": "Intel64 Family 6 Model 140 Stepping 1, GenuineIntel",
# "PROCESSOR_LEVEL": "6",
# "PROCESSOR_REVISION": "8c01",
# "PROGRAMDATA": "C:\\ProgramData",
# "PROGRAMFILES": "C:\\Program Files",
# "PROGRAMFILES(X86)": "C:\\Program Files (x86)",
# "PROGRAMW6432": "C:\\Program Files",
# "PSMODULEPATH": "C:\\Users\\admin123\\Documents\\WindowsPowerShell\\Modules;C:\\Program Files\\WindowsPowerShell\\Modules;C:\\windows\\system32\\WindowsPowerShell\\v1.0\\Modules",
# "PUBLIC": "C:\\Users\\Public",
# "PYTHONUNBUFFERED": "1",
# "RABBITMQ_SERVER": "C:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.12.12",
# "REGIONCODE": "APJ",
# "SESSIONNAME": "Console",
# "SSO_CLIENT_DIRECTORY": "c:\\sso_client\\",
# "SVN_EXPERIMENTAL_COMMANDS": "shelf2",
# "SYSTEMDRIVE": "C:",
# "SYSTEMROOT": "C:\\windows",
# "TEMP": "C:\\Users\\admin123\\AppData\\Local\\Temp",
# "TMP": "C:\\Users\\admin123\\AppData\\Local\\Temp",
# "USERDOMAIN": "DESKTOP-ES61745",
# "USERDOMAIN_ROAMINGPROFILE": "DESKTOP-ES61745",
# "USERNAME": "admin123",
# "USERPROFILE": "C:\\Users\\admin123",
# "VBOX_MSI_INSTALL_PATH": "C:\\Program Files\\Oracle\\VirtualBox\\",
# "VIRTUAL_ENV": "C:\\Users\\admin123\\Desktop\\tjhb\\huabao_screen\\huabao-screen-server\\venv",
# "VS140COMNTOOLS": "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\",
# "WINDIR": "C:\\windows",
# "ZES_ENABLE_SYSMAN": "1",
# "TERM_PROGRAM": "vscode",
# "TERM_PROGRAM_VERSION": "1.86.2",
# "LANG": "en_US.UTF-8",
# "COLORTERM": "truecolor",
# "GIT_ASKPASS": "c:\\Users\\admin123\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\extensions\\git\\dist\\askpass.sh",
# "VSCODE_GIT_ASKPASS_NODE": "C:\\Users\\admin123\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe",
# "VSCODE_GIT_ASKPASS_EXTRA_ARGS": "",
# "VSCODE_GIT_ASKPASS_MAIN": "c:\\Users\\admin123\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\extensions\\git\\dist\\askpass-main.js",
# "VSCODE_GIT_IPC_HANDLE": "\\\\.\\pipe\\vscode-git-adce85326b-sock",
# "VSCODE_INJECTION": "1",
# "_OLD_VIRTUAL_PATH": "C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Python27\\;C:\\Python27\\Scripts\\;C:\\Program Files (x86)\\AdoptOpenJDK\\jdk-8.0.292.10-openj9\\bin;C:\\windows\\system32;C:\\windows;C:\\windows\\System32\\Wbem;C:\\windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\Bandizip\\;C:\\Program Files\\TortoiseSVN\\bin;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files (x86)\\AdoptOpenJDK\\bin;C:\\Program Files (x86)\\AdoptOpenJDK\\jre\\bin;C:\\Program Files (x86)\\PuTTY\\;C:\\Program Files\\Git\\cmd;C:\\Users\\admin123\\AppData\\Roaming\\nvm;C:\\Program Files\\nodejs;C:\\Program Files\\AsiaInfo Security\\AisEsmAgent;C:\\Program Files\\Redis\\;C:\\Program Files\\Erlang OTP\\bin;C:\\Program Files\\RabbitMQ Server\\rabbitmq_server-3.12.12\\sbin;C:\\Python36\\Scripts\\;C:\\Python36\\;C:\\Users\\admin123\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\admin123\\Desktop\\tjhb\\mvn\\apache-maven-3.8.5\\bin;C:\\Users\\admin123\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Python27\\;C:\\Program Files\\mysql-5.7.38-winx64\\mysql-5.7.38-winx64\\bin;C:\\Python27\\Scripts\\;C:\\Users\\admin123\\AppData\\Roaming\\nvm\\v16.13.0;C:\\Users\\admin123\\AppData\\Roaming\\nvm;C:\\Program Files\\nodejs;C:\\Users\\admin123\\AppData\\Local\\Programs\\Python\\Python310\\;C:\\Users\\admin123\\AppData\\Local\\Programs\\Python\\Python310\\Scripts\\;C:\\Program Files\\MongoDB\\Server\\6.0\\bin;C:\\Program Files\\mysql-5.7.38-winx64\\mysql-5.7.38-winx64\\include;",
# "DJANGO_SETTINGS_MODULE": "settings",
# "RUN_MAIN": "true",
# "SERVER_NAME": "activate.navicat.com",
# "GATEWAY_INTERFACE": "CGI/1.1",
# "SERVER_PORT": "8000",
# "REMOTE_HOST": "",
# "CONTENT_LENGTH": "20",
# "SCRIPT_NAME": "",
# "SERVER_PROTOCOL": "HTTP/1.1",
# "SERVER_SOFTWARE": "WSGIServer/0.2",
# "REQUEST_METHOD": "POST",
# "PATH_INFO": "/cockpit/ttttt/",
# "QUERY_STRING": "AA=aa&BB=bb",
# "REMOTE_ADDR": "127.0.0.1",
# "CONTENT_TYPE": "application/json",
# "HTTP_COOKIE": "cookie1=11;cookie2=22",
# "HTTP_USER_AGENT": "PostmanRuntime/7.36.3",
# "HTTP_ACCEPT": "*/*",
# "HTTP_CACHE_CONTROL": "no-cache",
# "HTTP_POSTMAN_TOKEN": "7fc1e5ed-f218-4d00-af4d-a2152ad30740",
# "HTTP_HOST": "127.0.0.1:8000",
# "HTTP_ACCEPT_ENCODING": "gzip, deflate, br",
# "HTTP_CONNECTION": "keep-alive",
# "wsgi.input": <django.core.handlers.wsgi.LimitedStream object at 0x00000133CB0F6748>,
# "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">
# }
# CONTENT_LENGTH —— 请求的正文的长度(是一个字符串)。
# CONTENT_TYPE —— 请求的正文的MIME 类型。
# HTTP_ACCEPT —— 响应可接收的Content-Type。
# HTTP_ACCEPT_ENCODING —— 响应可接收的编码。
# HTTP_ACCEPT_LANGUAGE —— 响应可接收的语言。
# HTTP_HOST —— 客服端发送的HTTP Host 头部。
# HTTP_REFERER —— Referring 页面。
# HTTP_USER_AGENT —— 客户端的user-agent 字符串。
# QUERY_STRING —— 单个字符串形式的查询字符串(未解析过的形式)。
# REMOTE_ADDR —— 客户端的IP 地址。
# REMOTE_HOST —— 客户端的主机名。
# REMOTE_USER —— 服务器认证后的用户。
# REQUEST_METHOD —— 一个字符串,例如"GET" 或"POST"。
# SERVER_NAME —— 服务器的主机名。
# SERVER_PORT —— 服务器的端口(是一个字符串)。
python3.X - Web - Django3.2.9
整章节共43节
快分享给你的小伙伴吧 ~