【发布时间】:2016-01-02 12:06:49
【问题描述】:
我很难找到匹配所有传入 url 的通配符 url 匹配模式。这只是匹配一个只有主机名的 url:
import asyncio
from aiohttp import web
@asyncio.coroutine
def handle(request):
print('there was a request')
text = "Hello "
return web.Response(body=text.encode('utf-8'))
@asyncio.coroutine
def init(loop):
app = web.Application(loop=loop)
app.router.add_route('GET', '/', handle)
srv = yield from loop.create_server(app.make_handler(),
'127.0.0.1', 9999)
print("Server started at http://'127.0.0.1:9999'")
return srv
loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))
try:
loop.run_forever()
except KeyboardInterrupt:
pass
因此,无论路径如何,只要有请求,它就应该调用处理程序。如果是http://127.0.0.1:9999/ 或http://127.0.0.1:9999/test/this/test/
我在这里查了http://aiohttp.readthedocs.org/en/stable/web.html#aiohttp-web-variable-handler,没有找到正确的线索
【问题讨论】:
标签: python python-3.x python-asyncio aiohttp