python - 如何在 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()
我的问题在于我无法处理如下链接: http://localhost:8080/get_something?from=20&to=24
解决方案
订阅/do_something
( @routes.get('/do_something')
)。所有查询参数都传递到匹配的 Web 处理程序中。
推荐阅读
- r - 优化在数据帧的多个列中查找案例和控件之间最短距离的过程
- node.js - 模型产品上的属性“类别”和关联“类别”之间的命名冲突
- flutter - 跟踪我的全局 dart 变量的最佳方法(我可以重新分配和读取)
- ag-grid - 展开和关闭图标将始终自动出现在组列中,虽然我没有设置 columnGroupShow
- java - 实体类的两个hashmap
- spring - 配置 spring boot 以重定向某些 url 上的某些错误
- c++ - 概念示例的简单 C++ 接口
- selenium-webdriver - 将列表的值拖放到页面的随机区域,不起作用
- dart - 命名构造函数是 Dart 中生成构造函数的子集吗?
- javascript - 在 React Native 中需要非静态图像