【FLASK】上传文件

前端之家收集整理的这篇文章主要介绍了【FLASK】上传文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
## 后端:


import
os from flask import request,jsonify from werkzeug.utils secure_filename Flask,request hashlib time app = Flask(__name__) @app.route('/upload',methods=[GETPOST']) def upload_file(): if request.method == : file = request.files[file] print(file.filename) basepath = os.path.dirname(__file__) # 当前文件所在路径 加密文件 file_name = md5(file.filename) + ".jpg" upload_path = os.path.join(basepath,1)">static/ 储存路径 (upload_path) file.save(upload_path) 保存文件 dict_data = {message": 上传成功} return jsonify(dict_data) md5(string): ctime = str(time.time()) m = hashlib.md5(bytes(string,encoding=utf-8)) m.update(bytes(ctime,encoding=)) m.hexdigest() if __name__ == __main__: app.run(debug=True)
# 前端

<!DOCTYPE html>
<html lang=en">
<head>
    <Meta charset=UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>文件上传示例</h1>
    <form action="" enctype=multipart/form-data' method='>
        <input type=" name=">
        <input type=submit" value=上传">
    </form>
</body>
</html>

 

猜你在找的Flask相关文章