记录一下实现过程和代码
from flask import Flask,render_template,request,redirect,url_for
from werkzeug.utils import secure_filename
import os
app = Flask(__name__)
@app.route('/uppload', methods=['POST', 'GET'])
def upload():
if request.method == 'POST':
f = request.files['file']
basepath = os.path.dirname(__file__)
upload_path = os.path.join(basepath, 'static/images',secure_filename(f.filename))
f.save(upload_path)
return redirect(url_for('upload'))#重定向到页面
return render_template('upload.html')
if __name__ == '__main__':
app.run(debug=True)
html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Flask上传图片演示</title>
</head>
<body>
<div>
&