Python 我尝试在Flask中使用404错误处理的蓝图,但我似乎无法使其工作。这是我的密码:

Python 我尝试在Flask中使用404错误处理的蓝图,但我似乎无法使其工作。这是我的密码:,python,flask,error-handling,http-status-code-404,blueprint,Python,Flask,Error Handling,Http Status Code 404,Blueprint,错误/处理程序.py from flask import render_template from autoapp import app from dockblaster.errors import errors_blueprint @app.errorhandler(404) @errors_blueprint.app_errorhandler(404) def not_found_error(error): return render_template('error_pages/

错误/处理程序.py

from flask import render_template
from autoapp import app
from dockblaster.errors import errors_blueprint


@app.errorhandler(404)
@errors_blueprint.app_errorhandler(404)
def not_found_error(error):
    return render_template('error_pages/page_not_found.html'), 404
错误/\uuuu初始化.py:

from flask import Blueprint
errors_blueprint = Blueprint('errors', __name__)
import dockblaster.errors
def create_app(config_object=ProdConfig):

"""An application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/.
:param config_object: The configuration object to use.
"""

app = Flask(__name__.split('.')[0])
app.config.from_object(config_object)

from dockblaster.errors import errors_blueprint
app.register_blueprint(errors_blueprint)

register_extensions(app)
register_blueprints(app)
return app
我终于在app.py:

from flask import Blueprint
errors_blueprint = Blueprint('errors', __name__)
import dockblaster.errors
def create_app(config_object=ProdConfig):

"""An application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/.
:param config_object: The configuration object to use.
"""

app = Flask(__name__.split('.')[0])
app.config.from_object(config_object)

from dockblaster.errors import errors_blueprint
app.register_blueprint(errors_blueprint)

register_extensions(app)
register_blueprints(app)
return app

我似乎无法实现这一点,因为我为404错误重定向创建的页面无法通过错误蓝图访问。

我能够自己解决这一问题

我这样做:

我删除了errors/handlers.py文件,并将代码添加到errors/int.py,从而避免了另一个文件导入来访问blueprint处理程序以查找错误。这似乎对我有用