10
すべての着信URLに一致するワイルドカードURL一致パターンを見つけることができません。これは単なるホスト名以上のものを持っていないURLに一致します。Asyncioとaiohttpがすべてのurlsパスをハンドラにルーティングします
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/
場合、私はあなたがすべてのURLをキャッチするためにapp.router.add_route('GET', '/{tail:.*}', handle)
を使用することができます右の手掛かり