Flask 中的 CBV 与上传文件
from flask import Flask, views, render_template, request app = Flask(__name__) app.config['DEBUG'] = True class Upload(views.MethodView): def get(self): return render_template('upload.html') def post(self): my_file = request.files.get('file') print(my_file) my_file.save(my_file.filename) return 'upload success!' app.add_url_rule('/upload', view_func=Upload.as_view(name='upload')) if __name__ == '__main__': app.run()