python大佬养成计划----基于flask上传文件
上传文件
实现目标: 如何将文件上传到服务器(保存在指定的文件夹)
# 需要建立当前工作环境下的/static/face/目录,文件会保存在此目录下 import os from flask import Flask,render_template,request import uuid app = Flask(__name__) @app.route('/upload/',methods=['GET','POST']) def upload(): if request.method == 'POST': # 获取到用户上传的文件对象 f = request.files['faceImg'] print(f.filename) # 获取当前项目所在目录位置; basepath = os.path.dirname(__file__) print(basepath) # 拼接路径, 存储文件到static/face/xxxx filename = os.path.join(basepath, 'static/face', f.filename) f.save(filename) return render_template('demo/upload.html', message="上传成功") else: return render_template('demo/upload.html') app.run()
相关推荐
bestallen 2020-08-17
JessePinkmen 2020-07-26
washing 2020-07-18
hzyuhz 2020-07-04
hzyuhz 2020-06-28
hzyuhz 2020-06-25
苦咖啡flask 2020-06-25
苦咖啡flask 2020-06-25
苦咖啡flask 2020-06-18
washing 2020-06-16
liuweiq 2020-06-14
wushaojun 2020-06-14
JessePinkmen 2020-06-14
kgshuo 2020-06-14
JessePinkmen 2020-06-14
bestallen 2020-06-13