简体   繁体   中英

How do I handle form data in aiohttp responses

I'm looking to get the multipart form data and turn it into a dictionary. Easy enough for json, but this seems to be a bit different.

Current code:

app = web.Application()

async def deploy(request):
    # retrieve multipart form data or
    # x-www-form-urlencoded data
    # convert to a dictionary if not already
    text = "Hello"
    return web.Response(text=text)
app.router.add_post('/', deploy)

web.run_app(app)

You can use the request.post() method.

app = web.Application()

async def deploy(request):
    # retrieve multipart form data or
    # x-www-form-urlencoded data
    data = await request.post()
    print(data)
    text = "Hello"
    return web.Response(text=text)

app.router.add_post('/', deploy)

web.run_app(app)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM