from flask import Flask,render_template,request
app=Flask(__name__)
@app.route('/upload/',methods=['GET','POST'])
def upload():
if request.method=='POST':
file_obj=request.files.get('picture')
print(file_obj) #<FileStorage: '1.jpg' ('image/jpeg')>
print(type(file_obj.filename),file_obj.filename) #获取上传文件名称
path='static/'+file_obj.filename
#第一种保存方法
#with open(path,mode='wb') as f:
# f.write(file_obj.read())
#第二种保存方式
file_obj.save()
return '上传成功了'
return render_template('upload.html')
if __name__ == '__main__':
app.run()
Flask---文件上传
猜你喜欢
转载自blog.csdn.net/weixin_44111377/article/details/92005176
今日推荐
周排行