Skip to content
Advertisement

ImportError: cannot import name ‘app’ from partially initialized module ‘market’ (most likely due to a circular import)

I was trying to package my code as it was getting kind of complex for me to keep in one file and i encountered an import error when i tried to run the file that says circular import error, how do i solve this error? I have been analyzing the code and i cannot seem to be able to figure out what might be wrong.

run.py

JavaScript

init.py

JavaScript

routes.py

JavaScript

models.py

JavaScript

project structure enter image description here

error enter image description here

Advertisement

Answer

Moving your routes import to the bottom of the file should help.

Just as you would do for example with blueprints in application factory. You import blueprints/views after you create app instance with app = Flask(__name__):

JavaScript

Also check: Is a Python module import at the bottom ok?

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement