Alexander2019-03-08 16:38:57
Alexander, 2019-03-08 16:38:57

Aiohttp asyncpgsa how to give json?

Hello, help me send json when requesting, I have a view

async def cars(request):
        Возвращаем все машины из бд
    async with request.app['db'].acquire() as conn:
        query = select([car])
        result = await conn.fetch(query)
    return web.Response(body=str(result))

Now in the result variable I get a list with objects
[<Record id=1 brand='Lada priora' number='e456xe97'>, <Record id=2 brand='bmw x5' number='e123xd56'>]

How can I serialize this list in json format?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
alternativshik, 2019-03-08

dict(result) In general, the dock has https://asyncpgsa.readthedocs.io/en/latest/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question