[英]Flask View from table of a sqlalchemy-bind doesn't work
I'm using python 3.6.5, flask 1.0.2, flask-admin, flask-sqlalchemy我正在使用 python 3.6.5、flask 1.0.2、flask-admin、flask-sqlalchemy
I have problems showing a View of a table from a second database, sqlalchemy bind configuration, model database, model view all seem like it's ok, but view is not showed in the app, and when I try to force it through the URL, a permissions message appears.我在显示来自第二个数据库、sqlalchemy 绑定配置、模型数据库、模型视图的视图时遇到问题,看起来一切正常,但是应用程序中没有显示视图,当我尝试通过 URL 强制它时,一个出现权限消息。
I have checked the bind configuration, when I comment that line, the expected error appears.我已经检查了绑定配置,当我评论该行时,出现了预期的错误。
I also removed and added some other views from primary database's tables, all of that work well.我还从主数据库的表中删除并添加了一些其他视图,所有这些都运行良好。
I have tried with different ways to make reference to db.session:我尝试了不同的方法来引用 db.session:
db.session #like always
db.session(bind=['login'])
db.get_engine(app, 'login')
None of that report any error, but view doesn't work.这些都没有报告任何错误,但视图不起作用。
SQLALCHEMY_BINDS configuration: SQLALCHEMY_BINDS 配置:
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://user:pass@localhost/radius'
SQLALCHEMY_BINDS = {
'login': 'mysql+pymysql://user:pass@localhost/login_radisp'
}
db Model:数据库型号:
class Empleado(db.Model):
__bind_key__ = 'login_radisp'
__tablename__ = 'empleados'
id_empleado = Column(INTEGER, primary_key=True)
nombre = Column(String(255))
apellido = Column(String(255))
email = Column(String(255))
db Model View数据库模型视图
class EmpleadoAdmin(sqla.ModelView):
column_labels = dict(
nombre = 'Nombre',
apellido = 'Apellido',
telefono = 'Teléfono',
email = 'Email'
Creating app builder objects:创建应用程序构建器对象:
admin.add_view(EmpleadoAdmin(Empleado, db.session(bind=['login'])))
There is not error at all, but view is not showed in the app, when I try to force the view in the URL, next message appears:根本没有错误,但是应用程序中没有显示视图,当我尝试在 URL 中强制视图时,出现下一条消息:
Forbidden
You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.
This is a DB access problem, not a flask-admin issue.这是一个数据库访问问题,而不是一个烧瓶管理问题。 Check your "SQLALCHEMY_BINDS" access
检查您的“SQLALCHEMY_BINDS”访问权限
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.