烧瓶 - 发生蓝图名称冲突

问题描述:

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

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. 

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

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 
# @first_date 20160129 
# @date   20160129 
# @version  0.0 
"""Init flask app 
""" 
from flask import Flask 

from flask.ext.bootstrap import Bootstrap 
from flask.ext.sqlalchemy import SQLAlchemy 
from flask.ext.marshmallow import Marshmallow 
from flask.ext.login import LoginManager 

import configs 


# Initializing process: This package is main flask app 
app = Flask(__name__) 
app.config.from_object(configs.CONFIGS['default']) 


# Initializing process: This extesion list is created extension object 
bootstrap = Bootstrap() 
db = SQLAlchemy() 
ma = Marshmallow() 


login_manager = LoginManager() 
login_manager.session_protection = "strong" 
login_manager.login_view = 'users.login' 


def init_extensions(app): 
    '''Initializing the flask app with extensions''' 
    # Extension List: Wrap up the all extensions 
    extensions = (
     bootstrap, 
     db, 
     ma, # Warning: Flask-SQLAlchemy must be initialized before Flask-Marshmallow. 
     login_manager, 
    ) 
    # Initializing process: Start to initial each extension 
    for extension in extensions: 
     extension.init_app(app=app) 



def init_blueprints(app): 
    '''Initializing the flask app with blueprints''' 
    # Blueprint source: Import the blueprints and note these sources 
    from .views import users 

    from .web import web_bp 

    # Blueprint List: Wrap up the all blueprints 
    buleprints = (
     dict(blueprint=users.users_bp, url_prefix='/users'), 

     dict(blueprint=web_bp, url_prefix=''), 
    ) 

    # Initializing process: Start to initial each blueprint 
    for blueprint in buleprints: 
     app.register_blueprint(**blueprint) 


def init_error_handlers(app): 
    '''import error handler function''' 
    from .error_handlers.built_in_exception_handlers import * 
    from .error_handlers.status_code_handlers import * 
    from .error_handlers.sqlachelmy_handlers import * 


def create_app(): 
    '''It's a factory.''' 
    # Initializing process: Initializing the main flask app with extensions 
    init_extensions(app) 

    # Initializing process: Initializing the main flask app with blueprints 
    init_blueprints(app) 

    # Initializing process: import error handlers 
    init_error_handlers(app) 

    return app 

或任何人可以告诉我如何查找在应用程序的蓝图对象,让我跟踪的bug。谢谢。

+0

你有其他模块导入这个脚本? –

+0

@MartijnPieters我在创建应用程序函数之前没有导入任何模块。 – Tony

看起来你的应用程序注册了两次Bootstrap蓝图。有一个在引导的源代码行这确实注册它在init_app()

尝试无论是从这里将其取出:

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

或从本元组:

# Blueprint List: Wrap up the all blueprints 
    buleprints = (
     dict(blueprint=users.users_bp, url_prefix='/users'), 

     dict(blueprint=web_bp, url_prefix=''), 
    )