AssertionError: A blueprint's name collision occurred

好久不见. 提交于 2019-12-11 18:57:19

问题


I'm trying to extend the flask-base project https://github.com/hack4impact/flask-base/tree/master/app. This uses the the application factory pattern in app/init.py and blueprints.

I'm struggling to get the most basic functionality working so now I'm trying to follow https://flask-admin.readthedocs.io/en/v1.1.0/_sources/quickstart.txt

In the app/init.py I have:

from flask_admin import Admin


....
adm = Admin(name='admin2')


def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    # not using sqlalchemy event system, hence disabling it

    config[config_name].init_app(app)
....
    RQ(app)
    adm.init_app(app)   
...

from .admin import admin as admin_blueprint
app.register_blueprint(admin_blueprint, url_prefix='/admin')

return app

templates/admin/db.html:

<p>Hello world</p>

To the admin views (https://github.com/hack4impact/flask-base/blob/master/app/admin/views.py) I've added :

from flask_admin import Admin, BaseView, expose
from flask_admin.contrib.sqla import ModelView
from app import adm, db

class MyView(ModelView):
    @expose('/')
    # @login_required
    def db(self):
        return self.render('admin/db.html')


adm.add_view(MyView(User, db.session))

When I open:

 127.0.0.1:5000/db

I get:

AssertionError: A blueprint's name collision occurred between <flask.blueprints.Blueprint object at 0x000000000586C6D8> and <flask.blueprints.Blueprint object at 0x00000000055AFE80>.  Both share the same name "admin".  Blueprints that are created on the fly need unique names.

What am I doing wrong?

edit:

following your advice I changed to:

adm = Admin(name='admin2',endpoint='/db')

However if I try:

 127.0.0.1:5000/db/db

I get a 404. I'm assuming you are changing the normal base admin route from 'admin'to 'db'

What now?


回答1:


If my answer in Wrong dashboard while adding flask-admin to project solved your problem, then I believe it would be better to close this question.

If not, let me know



来源:https://stackoverflow.com/questions/50118046/assertionerror-a-blueprints-name-collision-occurred

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!