我正在尝试扩展基于烧瓶的项目https://github.com/hack4impact/flask-base/tree/master/app。这使用了app / init.py和蓝图中的应用程序工厂模式。
我正努力让最基本的功能正常工作,所以现在我正试图关注https://flask-admin.readthedocs.io/en/v1.1.0/_sources/quickstart.txt
在app / init.py中我有:
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
模板/管理/ db.html:
<p>Hello world</p>
我添加了管理员观点(https://github.com/hack4impact/flask-base/blob/master/app/admin/views.py):
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))
当我打开时:
127.0.0.1:5000/db
我明白了:
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.
我做错了什么?
编辑:
根据您的建议,我改为:
adm = Admin(name='admin2',endpoint='/db')
但是,如果我尝试:
127.0.0.1:5000/db/db
我得到了404.我假设您正在将正常的基本管理路由从'admin'更改为'db'
现在怎么办?