flask, models 文件夹内的数据库模型文件,引用失败,求解?

图片描述

我想在 theme.py 里引入 theme_product
使用 from . import theme_product 就可以
使用 from .theme_product import Theme_Product
就提示 cannot import name 'Theme_Product'
大写的 Theme_product 是 theme_product 的中的数据库类
--------分隔线---------

product,theme,是多对多关系,theme_product 是中间表
from . import theme_product
theme=db.relationship('Theme_Product',

                        foreign_keys=[theme_product.Theme_Product.product_id],
                        backref=db.backref('backProduct',lazy='joined'),
                        lazy='dynamic',
                        cascade='all,delete-orphan')

foreign_keys 那里告诉我 theme_product 没有 Theme_Product,这个 attribute
应该如何处理呢?

阅读 2.1k
1 个回答

你可以试试这样

from models.theme_product import Theme_Product

如果这个还不行,试试这个

from 项目目录.models.theme_product import Theme_Product
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题