这是我的模型,适用于具有布尔字段admin的用户:
class User(db.Model, UserMixin):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
lastname = db.Column(String(50), unique=False, nullable=False)
firstname = db.Column(String(50), unique=False, nullable=False)
username = db.Column(db.String(64), unique=True, index=True)
email = db.Column(db.String(64), unique=True, nullable=False, index=True)
password_hash = db.Column(db.String(128))
admin = db.Column(Boolean)
created_date = db.Column(Date, nullable=True)
lastupdate_date = db.Column(Date, nullable=True)
def __init__(self,lastname,firstname,email,username,password, admin, created_date):
self.email = email
self.lastname = lastname
self.firstname = firstname
self.username = username
self.password_hash = generate_password_hash(password)
self.admin = admin
self.created_date=created_date
def __repr__(self, email, lastname, firstname, admin):
return f"User {self.id} is {self.email}, {self.lastname}. administrator: {self.admin}"
def check_password(self,password): # check if password is ok when login
return check_password_hash(self.password_hash,password)
我的模板是:
<div class="jumbotron">
<h1>Here is a list of all available users.</h1>
<ul>
{% for user in users %}
<li>{{user}}</li>
{% endfor %}
</ul>
</div>
app.py是这样的:
@app.route('/listofuser')
@login_required
def listofuser():
listusers = User.query.all()
return render_template('listofuser.html', users=listusers)
我的错误是:typeerror:repr()缺少4个必需的位置参数:“email”、“lastname”、“firstname”和“admin”
我已经检查了数据库,一切正常。为什么我会有这个错误?
暂无答案!
目前还没有任何答案,快来回答吧!