Flask系列07--Flask中的CBV, 藍圖的CBV
阿新 • • 發佈:2019-04-11
div gin col flask [] django pan cbv func
一.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)
Flask系列07--Flask中的CBV, 藍圖的CBV