1.前端代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form action="http://127.0.0.1:8888/login" method="post" enctype="multipart/form-data"> <input type="file" name="file" /><br /> <input type="submit" value="Upload" /> </form> </body> </html>
2.后台接收文件的代码(flask)
from flask import Flask, jsonify, request, json from werkzeug.utils import secure_filename app = Flask(__name__) @app.route("/login", methods=["POST"]) def epwk_generate(): username = request.values.get("username") file_hello = request.files f = request.files["file"] # 上传文件 filename = secure_filename(f.filename) f.save('./hh.' + str(filename)) return 'ok' if __name__ == '__main__': app.run(host='127.0.0.1',port=8888, debug=False)