Answer the question
In order to leave comments, you need to log in
How to set default user role when registering with Flask-User?
Can't figure out how to set the default role? It is necessary for sampling when displaying users in the admin panel.
DB Schema:
class Role(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), unique=True)
description = db.Column(db.Text(255))
def __repr__(self):
return self.id
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), nullable=False, unique=True)
password = db.Column(db.String(150), nullable=False)
email = db.Column(db.String(30))
is_enabled = db.Column(db.Boolean(), nullable=False, default=True)
roles = db.relationship('Role', secondary='user_roles',
backref=db.backref('users', lazy='dynamic'))
def is_active(self):
return self.is_enabled
class UserRoles(db.Model):
id = db.Column(db.Integer(), primary_key=True)
user_id = db.Column(db.Integer(), db.ForeignKey('user.id', ondelete='CASCADE'))
role_id = db.Column(db.Integer(), db.ForeignKey('role.id', ondelete='CASCADE'))
@user_registered.connect_via(app)
def user_registered_sighandler(app, user, confirm_token):
default_role = user_datastore.find_role("user")
user_datastore.add_role_to_user(user, default_role)
db.session.commit()
Answer the question
In order to leave comments, you need to log in
I did not particularly suffer from the choice, I installed the FTP server according to the first manual for CentOS that came across. There were no problems.
Of course, it is more convenient to immediately upload files to the server. Any client will do, such as FileZilla .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question