1 # -*- coding:utf-8 -*- 2 from flask import Flask,request,render_template,redirect,url_for 3 from os import path 4 from werkzeug.utils import secure_filename 5 6 app = Flask(__name__) 7 8 @app.route('/upload',methods=['GET','POST']) 9 def upload(): 10 if request.method=='POST': 11 f = request.files['file'] 12 basepath = path.abspath(path.dirname(__file__)) 13 upload_path = path.join(basepath,'static/uploads') 14 f.save(path.join(upload_path,secure_filename(f.filename))) 15 return redirect(url_for('upload')) 16 return render_template('upload.html') 17 18 if __name__ == '__main__': 19 app.run(debug=True)
14行中加入path.join()