Django图片上传

Python Web 学习之图片上传

1
2
3
4
5
6
7
8
9
10
11
12
def c(request):
print(request.GET)
print(request.POST)
print(request.FILES)
for item in request.FILES:
file = request.FILES.get(item)
file_name = file.name
with open(file_name, 'wb') as f:
for line in file.chunks():
f.write(line)

return render(request, "index.html")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>Hello World</h1>
<form action="/ctl/" method="post" enctype="multipart/form-data">

<p><input type="file" name="文件"></p>
<p><input type="submit" value="提交"></p>

</form>
</body>
</html>
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2017-2021 More Star

请我喝杯咖啡吧~

支付宝
微信