我有一个在Model类中定义的类方法,但每次调用它时都会出现属性错误。
在我的Model类中:
@classmethod
def find_all_models(cls):
models= Db.get_session().query(cls).all()
return models
在金字塔视图中调用:
from mlc.model.model import Model as MyModel
model_choices=MyModel.find_all_models()
我得到错误:
AttributeError:类型对象'Model'没有属性'find_all_models'
我确信我的导入路径是正确的。甚至Eclipse也会看到这个方法并在我输入时自动填充它。我还应该检查什么?