如何在 aiohttp 中设置查询处理程序
how set query handler in aiohttp
我有下一个代码:
from aiohttp import web
PORT = 8080
HOST = 'localhost'
routes = web.RouteTableDef()
@routes.get('/do_something?from={f}&to={s}')
async def test_get(request):
return web.json_response({request.match_info['f']: request.match_info['s']})
#return web.json_response({request.match_info['FROM']: request.match_info['TO']})
def start_app():
app = web.Application()
app.add_routes(routes)
web.run_app(app, port=PORT, host=HOST)
if __name__ == '__main__':
start_app()
我的问题在于我无法处理 link,例如:
http://localhost:8080/get_something?from=20&to=24
订阅 /do_something
(@routes.get('/do_something')
)。所有查询参数都传递到匹配的网络处理程序中。
我有下一个代码:
from aiohttp import web
PORT = 8080
HOST = 'localhost'
routes = web.RouteTableDef()
@routes.get('/do_something?from={f}&to={s}')
async def test_get(request):
return web.json_response({request.match_info['f']: request.match_info['s']})
#return web.json_response({request.match_info['FROM']: request.match_info['TO']})
def start_app():
app = web.Application()
app.add_routes(routes)
web.run_app(app, port=PORT, host=HOST)
if __name__ == '__main__':
start_app()
我的问题在于我无法处理 link,例如: http://localhost:8080/get_something?from=20&to=24
订阅 /do_something
(@routes.get('/do_something')
)。所有查询参数都传递到匹配的网络处理程序中。