Jur*_*ocs 17 python python-3.x python-asyncio aiohttp
我很难找到匹配所有传入网址的通配符网址匹配模式.这只匹配一个只有主机名的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
Run Code Online (Sandbox Code Playgroud)
因此,无论路径如何,它都应该在有请求时随时调用处理程序.如果是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没有成功找到合适的线索
And*_*lov 31
您可以app.router.add_route('GET', '/{tail:.*}', handle)用来捕获所有网址.
| 归档时间: |
|
| 查看次数: |
5318 次 |
| 最近记录: |