from sanic import Blueprint
from sanic.response import json
from sanic import Sanic
app = Sanic('test')
bpv1 = Blueprint('bpv1', version=1)
@bpv1.route('/hello')
async def root(request):
return json('hello v1')
app.blueprint(bpv1)
bpv2 = bpv1.copy('bpv2', version=2)
@bpv2.route('/hello')
async def root(request):
return json('hello v2')
app.blueprint(bpv2)当路由属于不同的蓝图时,我想部分地覆盖它们的实现,但是它提出了sanic_routing.exceptions.RouteExists。
我怎么才能得到这个目标?
发布于 2022-09-28 09:48:39
我从论坛上得到了答案。
bpv2 = bpv1.copy("bpv2", version=2)
bpv2._future_routes = {
route for route in bpv2._future_routes if route.uri != "/hello"
}
@bpv2.route("/hello")
async def root2(request):
return json("hello v2")链路
https://community.sanicframework.org/t/how-to-overwrite-a-route-when-using-blueprint-copy/1067
https://stackoverflow.com/questions/73850187
复制相似问题