from flask import Flask,views,render_template,request
app = Flask(__name__)
app.debug = True
class LoginView(views.MethodView):
def __render(self,error=None):
return render_template('login.html', error=error)
def get(self,):
return self.__render()
def post(self):
username = request.form.get('username')
password = request.form.get('password')
if username == 'xiaowu' and password == '123456':
return 'login success'
return self.__render(error="用户名和密码错误")
def put(self): pass def delete(self): pass
app.add_url_rule('/login/',view_func=LoginView.as_view('login'))
if __name__ == '__main__':
app.run()
Flask优雅的注册蓝图及自定义MethodView
最新推荐文章于 2024-01-09 09:22:03 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)