I'm currently developing a web app using flask. my current workflow is to run the following on the command line.
$ set FLASK_APP=run.py
$ flask run
This has been working fine, but for some reason, imports break whenever I try to run differently via
$ python run.py
This is my file structure
init.py
app.py
run.py
database/
models.py
calculators/
calc.py
This is my run file:
from .app import create_app, create_db # this breaks
from flask_migrate import Migrate
app = create_app()
db = create_db(app)
migrate = Migrate(app,db, compare_type=True)
if __name__ == "__main__":
app.run(debug=True)
I can fix the import issue within run.py by changing .app to app
However, removing a period does not work for my models.py when it tries to reference calc.py
from ..calculators import calc #this line breaks
# ..More python code..
I continue getting the error ValueError: attempted relative import beyond top-level package
Is this supposed to happen? All the deployment software I find take advantage of a python run.py rather than flask run. Would I have to rewrite all my imports to fit one import scheme vs another?
If there's no short answer, I would appreciate it if there were any terms/documentation I could use that would help me get familiar / write the imports better. Thank you!