I have a similar project that is set up this way
project_root/ App1/ __init__.py FlaskControlPanel/ app.py static/ templates/ models/ __init__.py mymodels.py
Then I start everything starting with project_root . I have a small script (package or shell depending on my environment) that sets PYTHONPATH=. so that imports work correctly. This is because I usually develop using PyCharm, where the import "just works", but when I deploy the final product, the path does not match what it did in my IDE.
After PYTHONPATH has installed everything from the root of the project, you can perform standard import.
For example, from my FlaskControlPanel app.py , I have this line:
from models.mymodels import Model1, Model2, Model3
From App1 __init__.py I have the same import statement:
from models.mymodels import Model1, Model2, Model3
I can start the Flask application by executing it from my command line (on Windows) when I am in the project_root directory:
setlocal SET PYTHONPATH=. python FlaskControlPanel\app.py
setlocal used to ensure that PYTHONPATH changed only for this session.
source share