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

时间:2015-01-01 06:40:15

标签: python flask

flask dev服务器正在追加导致404错误的子类别网址。

这是我的网址结构......

/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)

TEMPLATE

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

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

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

1 个答案:

答案 0 :(得分:1)

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