How to get objects from model.User queried by Flask_SQLAlchemy

the result of the query is a model.user type, not a simple dict, so how can you use it like an object?

user = User.query.filter(User.username == username, User.password == password).first()

if you want to use user ["property"], you can use introspection to turn an object into dict, and generally speaking, objects are more convenient to have intelligent prompts and constraints. (if dict gets the value directly with the key in python, there is no:)), that will report an error unless you are accustomed to the way JS is written


.

you can take a look at this article to json sqlalchemy data .

of course, if you want to learn sqlalchemy, you can take a look at my project sql_to_sqlalchemy

.
def to_dict(model):
    return {c.name: getattr(model, c.name) for c in model.__table__.columns}
    
user = User.query.filter(User.username == username, User.password == password).first()
user_dict = to_dict(user)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9a626-17d0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9a626-17d0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?