我创建了一个带有404
错误处理程序的蓝图。但是,当我转到蓝图前缀下不存在的 url 时,会显示标准 404 页面而不是我的自定义页面。如何使蓝图正确处理 404 错误?
以下是演示该问题的简短应用程序。导航到http://localhost:5000/simple/asdf
不会显示蓝图的错误页面。
#!/usr/local/bin/python
# coding: utf-8
from flask import *
from config import PORT, HOST, DEBUG
simplepage = Blueprint('simple', __name__, url_prefix='/simple')
@simplepage.route('/')
def simple_root():
return 'This simple page'
@simplepage.errorhandler(404)
def error_simple(err):
return 'This simple error 404', err
app = Flask(__name__)
app.config.from_pyfile('config.py')
app.register_blueprint(simplepage)
@app.route('/', methods=['GET'])
def api_get():
return render_template('index.html')
if __name__ == '__main__':
app.run(host=HOST,
port=PORT,
debug=DEBUG)