我有以下烧瓶应用程序:
async def run():
conn = await asyncpg.connect(db_url)
values = await conn.fetch('''SELECT ... FROM ... WHERE ...;''')
await conn.close()
@app.route('/')
def test():
loop = asyncio.get_event_loop()
res = loop.run_until_complete(run())
return json.dumps([dict(r) for r in res])
if __name__ == '__main__':
app.run()
当我运行这段代码时,我得到了TypeError: 'NoneType' object is not iterable
。如何将我的values
转换为JSON?
您需要在
run
函数中返回值,以便它们在test
中可用:相关问题 更多 >
编程相关推荐