AttributeError:“函数”对象没有属性“名称”

2024-03-28 13:52:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我对烧瓶有意见。这是我的密码。我得到了错误
AttributeError: 'function' object has no attribute 'name'

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:1351996@localhost:5432/example'

db = SQLAlchemy(app)

class Person(db.Model):
    __tablename__ = 'persons'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(), nullable=False)

db.create_all()

@app.route('/')
def index():
    person = Person.query.first
    return 'Hello ' + person.name
    
if __name__ == '__main__':
    app.run(debug=True)

我使用了app.run(debug=True),因为我在尝试使用FLASK_APP=app.pyflask run运行应用程序时遇到了另一个错误,我不知道为什么会出现这个错误


Tags: runnamefromdebugimporttrueappflask