第九章 Flask——CBV模式
第九章 Flask——CBV模式
from flask import Flask,views,request,render_template app = Flask(__name__) class Login(views.MethodView): methods = ("POST","GET") def get(self): return render_template("index.html") def post(self): username = request.form.get("username") password = request.form.get("password") if username == "admin" and password == 123 : return "登录成功" return render_template("index.html",msg="登录失败") app.add_url_rule("/login",endpoint=None,view_func=Login.as_views(name="Login")) app.run("0.0.0.0",9527,debug=True)