我正在烧瓶应用程序中创建一条新路线。当我在'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呈现。
答案 0 :(得分:3)
不是N个字母引起错误,而是URL末尾的/
。
example.com/tableAdmin
和example.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。