为什么在 flask 应用程序的路由中放置单词 "Admin" 会导致页面出现 404?

Why does putting the word "Admin" in the route of a flask application cause the page to 404?

我正在我们的 Flask 应用程序中创建一条新路线。当我去添加一个 'n' 到 'tableAdmi' 的末尾时,它导致新路由到 404。这到底是什么导致的?

我有以下路线

@application.route('/console/tableAdmi')
def tableAdmin2wtf():
    return flask.render_template('formTest.html')

@application.route('/console/tableAdmin')
def editTable():
    return flask.render_template('formTest.html')

其他路由包含 Admin 一词,例如“/console/bulkAdministration”,并且在没有 404 的情况下呈现。

导致错误的不是字母 n,而是 URL 末尾的 /

example.com/tableAdminexample.com/tableAdmin/ 在此上下文中是不同的 URL。您需要单独处理它们或添加到同一个处理程序。

你可以这样做:

@application.route('/console/tableAdmin')
@application.route('/console/tableAdmin/')
def editTable():
    return flask.render_template('formTest.html')

和 URL 将变得与斜线无关。如果你想让你所有的 URL 斜杠不可知,你需要处理并删除 @app.before_request 中的斜杠。 有关详细信息,请参阅