如何修复间歇性 Flask Path Constructor 404?

How do I fix intermittent Flask Path Constructor 404?

flask 开发服务器附加子类别 urls 导致 404 错误。

这是我的 url 结构...

/services
/services/marketing/inbound
/services/marketing/outbound

我的期望是,如果我按此顺序导航,它们都会解决。但是,/service urls 正被 /service 像这样附加....

GET / HTTP/1.1" 200
GET /about HTTP/1.1" 200
GET /faq HTTP/1.1" 200
GET /contact HTTP/1.1" 200
GET /services/marketing HTTP/1.1" 200
GET /services/services/marketing/inbound HTTP/1.1" 404
GET /services/services/marketing/outbound HTTP/1.1" 404

查看

@app.route('/<path:path>')
def page(path):
    t = Tree(path)
    pg = t.get_page()  # return Page model object
    bc = t.build_path()  # returns bread-crumbs list ['/', 'services']
    mn = t.get_children() # returns sub-menu list ['inbound', 'out-bound']
    return render_template('page.html', pg=pg, bc=bc, mn=mn)

模板

<a href="services/medical-billing-quality-control">Billing Quality Control</a>

我也试过这个,但它也会导致 URL 构建错误。

<a href="{{ url_for('marketing', path=services) }}">Billing Quality Control</a>
werkzeug.routing.BuildError: ('medical-collections',
         {'path': 'services'}, None)

在您的 URL 中,href="services/etc" 应该是 href="/services/etc"(注意前导斜杠)。否则,href 被解释为相对于当前路径 的资源路径 ,这不是您想要的。