I have an issue with Flask. Here's my code. I got the error
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)
I used app.run(debug=True) because I got another error when trying to run app using FLASK_APP=app.py, flask run and I don't know why this error appears to me!