Flask一个蓝图的名字发生了碰撞

2024-04-26 06:06:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我遇到了一个问题。控制台说发生了蓝图名称冲突,但我认为这不属于烧瓶bootsrap问题。我相信我有一些配置或未知的东西,它让我遇到了问题。在

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    app = create_app()
  File "D:\TONY\GitHub\private-home-flask-cuisine\db-example\app\__init__.py", line 79, in create_app
    init_extensions(app)
  File "D:\TONY\GitHub\private-home-flask-cuisine\db-example\app\__init__.py", line 46, in init_extensions
    extension.init_app(app=app)
  File "D:\TONY\GitHub\private-home-flask-cuisine\db-example\env\lib\site-packages\flask_bootstrap\__init__.py", line 137, in init_app
    app.register_blueprint(blueprint)
  File "D:\TONY\GitHub\private-home-flask-cuisine\db-example\env\lib\site-packages\flask\app.py", line 62, in wrapper_func
    return f(self, *args, **kwargs)
  File "D:\TONY\GitHub\private-home-flask-cuisine\db-example\env\lib\site-packages\flask\app.py", line 885, in register_blueprint
    (blueprint, self.blueprints[blueprint.name], blueprint.name)
AssertionError: A blueprint's name collision occurred between <flask.blueprints.Blueprint object at 0x034EA230> and <flask.blueprints.Blueprint object at 0x0349
7770>.  Both share the same name "bootstrap".  Blueprints that are created on the fly need unique names.

这是我的密码。我不知道发生了什么。在

^{pr2}$

或者任何人都可以告诉我如何在app中查找blueprint对象并让我跟踪bug。谢谢。在


Tags: inpygithubappflaskhomedbinit
1条回答
网友
1楼 · 发布于 2024-04-26 06:06:19

看起来你的应用程序注册了两次引导蓝图。引导程序的源代码中有一行代码将其注册到init_app()

尝试将其从此处删除:

    ...
    bootstrap,
    db,
    ma,  # Warning: Flask-SQLAlchemy must be initialized before Flask-Marshmallow.
    login_manager,

或者从这个元组:

^{pr2}$

相关问题 更多 >