2
I am developing an API in Python FLASK and need to show the result of a SELECT that I made via SQL ALCHEMY. But when I use return he just comes back the first ROW of SELECT.
The funny thing is that with "print" it displays all results without any problem.
Could someone help me in this mystery?
def lista_unidades():
uni = session.query(UnidadesMam).all()
for u in uni:
return json.dumps({'Unidade': u.nomeUni, 'Endereco': u.enderecoUni, 'Bairro': u.bairroUni, 'Cep': u.cepUni,
'Cidade': u.cidadeUni, 'Estado': u.estadoUni, 'Pais': u.paisUni})
It worked well it returns all results inside the data array
– Yves Romeiro
Can we do without array rsrs ?
– Yves Romeiro
This I don’t know, maybe there is some flask functionality to do this directly @Yvesromeiro: http://stackoverflow.com/questions/7102754/jsonify-a-sqlalchemy-result-set-in-flask, http://code.runnable.com/UiIDW0LvVMFPAAAM/how-to-return-json-from-flask-for-python
– Miguel