Issue
I have two user models for flask_login.:
class Admin(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(30))
password_hash = db.Column(db.String(200))
class Merchant(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(30))
password_hash = db.Column(db.String(200))
Now I want to load user in session:
@login_manager.user_loader
def load_user(user_id):
pass
I want to know how to load user from two models.
Solution
#You can create a permission
admin_permission = Permission(RoleNeed('admin'))
#protect a view with a principal for that need
@app.route('/admin')
@admin_permission.required()
def do_admin_index():
return Response('Only if you are an admin)
Answered By - anoynmous
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.