How to fix the error: ImportError: attempted relative import with no known parent package

116 Views Asked by At

I've: db = SQLAlchemy() inside init.py and I want to import db to models.py

When I try to do: from . import db I get the Error: ImportError: attempted relative import with no known parent package

I've tried several things like:

import db

from .. import db
 
from website import db

When I run from __init__ import db it shows no error until I run main.py, then it shows the error: ModuleNotFoundError: No module named 'init'

My program is structured like this:

> Web app 
    > main.py
    >website
       >__init__.py
       >auth.py
       >models.py
       >views.py
       >templates
           >base.html
           >login.html
           >home.html
           >sign-up.html

Please help!

0

There are 0 best solutions below