Flask SQLAlchemy,Postman returns a single data
Question:
When ı run this code in VSCode:
table_name = 'student'
query = f'SELECT * FROM {table_name}'
result = db.session.execute(query)
for elem in result:
print(dict(elem))
It prints every data in the table. But when I try it in Postman with return and GET method:
table_name = 'student'
query = f'SELECT * FROM {table_name}'
result = db.session.execute(query)
for elem in result:
return jsonify(dict(elem))
Returns only 1 data with id=1. I want to see all data in Postman. How can ı do that.
Answers:
Flask’s jsonify() returns ready response on the first element, loop breaks.
try: return jsonify(dict(result))
but result must be db.session.execute(…).fetchall()
When ı run this code in VSCode:
table_name = 'student'
query = f'SELECT * FROM {table_name}'
result = db.session.execute(query)
for elem in result:
print(dict(elem))
It prints every data in the table. But when I try it in Postman with return and GET method:
table_name = 'student'
query = f'SELECT * FROM {table_name}'
result = db.session.execute(query)
for elem in result:
return jsonify(dict(elem))
Returns only 1 data with id=1. I want to see all data in Postman. How can ı do that.
Flask’s jsonify() returns ready response on the first element, loop breaks.
try: return jsonify(dict(result))
but result must be db.session.execute(…).fetchall()