pythondjangopython-importimporterrorrelative-import

ImportError: attempted relative import beyond top-level package?


My code structure:

code structure 1

code structure 2

When I import model from accounts app to to_do app:

#in to_do/models.py
from ..accounts.models import Account

I have this error:

 File "/home/ghost/projects/django_projects/To_Do_App/to_do_list/to_do/models.py", line 2, in <module>
    from ..accounts.models import Account
ImportError: attempted relative import beyond top-level package

How to fix it?


Solution

  • I tried to import my model this way from accounts.models import Account
    and now it works, but pycharm says that's not corectly