"""
form表单上传文件类型的数据
1.method必须指定成post
2.enctype必须换成formdata multipart
"""
前端
"""
<form action=""method="post"enctype="multipart/form-data">
<p>username: <input type="text"></p>
<p>文件:<input type="file" name="file"></p>
<p><input type="submit"></p>
</form>
"""
后端
"""
if request.method=='POST':
files_obj=request.FILES.get('file')
with open(files_obj.name,'wb')as f:
for line in files_obj.chunks():# 推荐加上chunks方法 其实跟不加是一样的都是一行行的读取
f.write(line)
return render(request,'files.html')
"""
request对象方法
"""
request.method
request.POST
request.GET
request.FILES
request.body # 原生的浏览器发过来的二进制数据 后面详细的讲
request.path
request.path_info
request.get_full_path() 能过获取完整的url及问号后面的参数
"""
print(request.path) #/app02/home/
print(request.path_info) #/app02/home/
print(request.get_full_path()) #/app02/home/?username=haha