M
M
Michael2015-04-09 10:45:02
Flask
Michael, 2015-04-09 10:45:02

How to send the objects found in the database to the template?

Hello, there is a function like this ormka ponyorm

@db_session
def select_allvalid_users():
    users = select(x for x in User)
    print(type(users))
    print(users)
    return users

she returns

[User[1], User[2]]


when i try to return send this to the template

usr = select_allvalid_users()


    return jsonify(user = usr)

he tells me

TypeError: User[1] is not JSON serializable

how to return the object normally to the template so that it can be used in the object field in the template?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2015-04-09
@skipirich

This is a security problem and it is described here flask.pocoo.org/docs/0.10/security/#json-security
Now you need to do something like this to return the entire list

usr = select_allvalid_users()
return jsonify({"user":usr})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question