烧瓶,烧瓶表和皮夫选择不正确填充烧瓶表

时间:2020-02-28 16:27:16

标签: mysql flask peewee

在Windows 10,python 3,flask,flask表,peewee,mysql数据库中工作,并直接使用开箱即用的代码,但得到以下信息

table in web application

简单的Peewee模型编码

db = MySQLDatabase('proposalexperiments', user='root',
    passwd='Emerson#20', host='localhost' )

class BaseModel(Model):
    class Meta:
        database = db

class Users(BaseModel):
    id = PrimaryKeyField(null=False)
    firstname = TextField
    lastname = TextField   
    username = TextField
    password = TextField
    email= TextField

    class Meta:
        db_table = "users"

def find_all_users():
    query = Users.select()
    return query

简单的烧瓶编码以选择配置文件页面,以在表格中显示已登录的用户信息和所有用户信息

@app.route('/proposal-experiments/profile')
def profile():

    # Check if user is loggedin
    if 'loggedin' in session:
        # We need logged users info for the user so we can display it on the profile page
        cursor = db.cursor()
        cursor.execute('SELECT * FROM users WHERE UserName = %s', [session['username']])
        account = cursor.fetchone()
        # We need all the users info
        users = find_all_users()
        table = TableUsers(users)
        #table.border = True
        # Show the profile page with account info
        return render_template('profile.html', account=account, table=table)

    # User is not loggedin redirect to login page
    return redirect(url_for('login'))

我是不熟悉烧瓶的人,所以我可能会犯一个菜鸟错误,但是在查看了示例和脚本之后

1 个答案:

答案 0 :(得分:0)

您需要使用字段 instances ,而不是类本身。

firstname = TextField  # this is wrong!

执行此操作:

firstname = TextField()