Flask系列07--Flask中的CBV, 蓝图的CBV
一.CBV使用
class base view 和django中类似
class Login(views.MethodView): # methods=["POST","GET"] # decorators = [] def get(self): return "login" def post(self): return "post_login" app.add_url_rule("/login",view_func=Login.as_view(name="login"))
二.蓝图CBV
auth = Blueprint('auth', __name__) # 蓝图CBV class Login(views.MethodView): def get(self): pass def post(self): pass auth.add_url_rule('/login', view_func=Login.as_view(name='login'))
记得注册蓝图
app = Flask(__name__) app.register_blueprint(auth.auth)