'im trying to host my flask api on heroku, but when passing the path to my app, i get an import error
the error im getting: ImportError: attempted relative import with no known parent package
My folder structure:
-Backend
__init__.py- run.py
- procfile
__init.py:
has the create app method
run.py:
from . import create_app
if __name__ == "__main__":
app = create_app("config")
app.run(debug=True)
procfile:
web: gunicorn run:app
EDIT:
I rearranged the app structure by which:
- Backend
- init.py
- procifle
- extensions.py
- src
- init.py
- run.py
init.py:
empty
src/init.py:
from ..extensions import db,migrate
has the create app method
src/run.py:
from src import create_app
if __name__ == "__main__":
app = create_app("config")
app.run(debug=True)
so now the new error is:
- from ..extensions import db
- ImportError: attempted relative import beyond top-level package
Edit #2: another thing to point out is, that suppose in the run.py i do the following: from Backend import create_app()
I get the following error: no module named "Backend" why could that be?
Has anyone faced a similar issue and what can I do to solve it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
