
Web-Apps on Flask: How to Deal with Cyclic Imports - SimbirSoft
https://www.codeproject.com/Articles/5265893/Web-Apps-on-Flask-How-to-Deal-With-Cyclic-Imports
======
etiennebch
I have been using Flask for a while now (to code rest apis). The circular
import issue can be a pain. I blame most tutorials and examples out there for
this. As the article mentions, putting code in init.py can lead to issues
because the file is read when importing modules in the directory it is
declared. Better to keep it empty. Also tutorials rarely mention how to use
the factory pattern effectively which prevents most of the issue. This is how
flask extensions are implemented by the way, with init_app function doing the
initialization. Often instead, you see app = Flask() declared at the top of
the init.py Not to mention using the app.url_rule decorator on views (which
leads to importing the global object) instead of using blueprints to register
views and registering blueprints in the app factory

