为什么在Flask应用程序的路径中加上“ Admin”一词会导致页面转到404?

时间:2019-12-20 17:28:31

标签: python flask uwsgi

我正在烧瓶应用程序中创建一条新路线。当我在'tableAdmi'的末尾添加'n'时,它会导致新的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呈现。

Same html, one 404's

1 个答案:

答案 0 :(得分:3)

不是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中的斜杠。 有关更多详细信息,请参见this question