I have the following files inside a package called users:
file __init__.py:
from flask_sqlalchemy import SQLAlchemy
from .views import UserDetails, UserList
db = SQLAlchemy()
file models.py:
from users import db
class User(db.Model):
pass
and file views.py:
from .models import User
from users import db
#code
But the following Import exception had occurred:
Error: While importing "users", an ImportError was raised:
Traceback (most recent call last):
File "/var/www/microservices/venv/lib/python3.6/site-packages/flask/cli.py", line 240, in locate_app
__import__(module_name)
File "/var/www/microservices/Flask_Microservices/users/__init__.py", line 9, in <module>
from .views import UserDetails, UserList
File "/var/www/microservices/Flask_Microservices/users/views.py", line 5, in <module>
from .models import User
File "/var/www/microservices/Flask_Microservices/users/models.py", line 2, in <module>
from users import db
ImportError: cannot import name 'db'
Any idea about what is wrong in my imports?