Flask—CBV模式

一、CBV

from flask import Flask,render_template,views,request
app = Flask(__name__)

class Login(views.MethodView):
    # 可省略
    # methods = ["GET","POST"]
    def get(self):
        return render_template("login.html")

    def post(self):
        my_file = request.files.get("MyFile")
        my_file.save(my_file.filename)
        return "123"

# 使用此方式添加路由
app.add_url_rule("/login",view_func=Login.as_view(name="login"))

if __name__ == '__main__':
    app.run("0.0.0.0",9527,debug=True)

 

你可能感兴趣的:(Flask框架)