Python class method throws AttributeError Python class method throws AttributeError flask flask

Python class method throws AttributeError


The issue was twofold:

  1. The User.py file was in the models/ folder, meaning that my import was actually looking for the User class in the models.py file, which no longer existed but still was being imported without error because the models.pyc file was still around
  2. The import was incorrect for importing within a directory. it should have been from models.User import User, so long as the models/ folder is a module, so all I needed to do then was touch models/__init__.py.


>>> class foo(object):...     def __init__(self):...             pass...     @classmethod...     def classmethod(cls):...             return 0...>>> a = foo()>>> a.classmethod()0>>>