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?