What does super(User, self).__init__(**kwargs) mean Python -
this question has answer here:
i got somecode this:
class user(usermixin, db.model): #... def __init__(self, **kwargs): super(user, self).__init__(**kwargs) if self.role none: if self.email == current_app.config['flasky_admin']: self.role = role.query.filter_by(permissions=0xff).first() if self.role none: self.role = role.query.filter_by(default=true).first()
the code checking if user have role, if not, add default role user. when use generate fake user tool generate fake user, user didn't have role generate_fake function.
so if want add role user, how can call function when manage.py runs? or how can call function in shell?
i don't understand super(user, self).__init__(**kwargs)
, function under class user, why still need add (user, self) super?
all code above book: flask web development: developing web applications python, miguel grinberg
to put calling baseclass's __init__
method
Comments
Post a Comment