from flask_login import UserMixin, AnonymousUserMixin,LoginManager,login_user,login_required,current_user,logout_user
ogin_manager=LoginManager()
login_manager.login_view='login'###跳转登录的地址
login_manager.session_protection='strong'
@login_manager.user_loader
def load_user(id):
return User.query.get(int(id))
``@app.route('/api/login',methods=['POST'])
def api_login():
data=request.json
username=data['username']
password=data['password']
user_info = User.query.filter_by(NAME=username,
PWD=password).first()
if user_info:
login_user(user_info)
return jsonify({'code':200,'info':'success'})
else:
return jsonify({"status": 401,
"reason": "Username or Password Error"})
`
flask前后端分离登录
最新推荐文章于 2024-10-11 17:24:53 发布