文件上传 Pycharm的自动提示

发布时间 2023-11-22 22:23:29作者: 朱饱饱

## html注意编码方式
<form action="/index/" method="post" enctype="multipart/form-data">

<p>用户名:<input type="text" name="name"></p>
<p>密码:<input type="password" name="password"></p>
<p><input type="file" name="myfile"></p>
<p><input type="submit" value="提交"></p>
</form>

# views.py
def index(request):
file=request.FILES.get('myfile')
# 打开一个空文件,写入
with open(file.name,'wb') as f:
for line in file.chunks():
f.write(line)
return HttpResponse('文件上传成功')

 

 

 

Pycharm的自动提示:

from django.core.handlers.wsgi import WSGIRequest
# pycharm的自动提示
request=request # type: WSGIRequest