from sanic import Sanic
from sanic.response import text
app = Sanic("server1")
@app.route("/<foo>/<bar>")
async def endpoint(request, foo, bar):
return text(f"Did you know {foo=} and {bar=}?")
app.run(port=9992)
现在,让我们测试一下:
$ curl localhost:9991/hello/world -Li
HTTP/1.1 302 Found
Location: http://localhost:9992/hello/world
content-length: 0
connection: keep-alive
content-type: text/html; charset=utf-8
HTTP/1.1 200 OK
content-length: 35
connection: keep-alive
content-type: text/plain; charset=utf-8
Did you know foo='hello' and bar='world'?
我不是100%确定这是否是你想要的答案。但是,如果您想在Sanic中创建一个超级粗糙的代理服务器来重定向所有请求,那么类似的方法就可以了(请参见^{)
因此,我们有一个交通的去处:
现在,让我们测试一下:
相关问题 更多 >
编程相关推荐