戒酒的李白

【app.py】添加路由拦截器:错误路径跳转404

Showing 1 changed file with 4 additions and 0 deletions
@@ -6,5 +6,9 @@ app = Flask(__name__) @@ -6,5 +6,9 @@ app = Flask(__name__)
6 def hello_world(): # put application's code here 6 def hello_world(): # put application's code here
7 return session.clear() 7 return session.clear()
8 8
  9 +@app.route('/<path:path>')
  10 +def catch_all(path):
  11 + return render_template('404.html')
  12 +
9 if __name__ == '__main__': 13 if __name__ == '__main__':
10 app.run() 14 app.run()