I am learning flask from https://blog.miguelgrinberg.com/
I have application microblog with filename as microblog.py
from app import app
and I have directory named app
and it contains __init__.py
with below code
from flask import Flask
from config import Config
app = Flask( __name__ )
app.config.from_object(Config)
from app import routes
But when I run flask run
I am getting error as
ImportError: No module named 'app'
I understand like if I want to indicate a directory as a package then I have to include a __init__.py
inside the directory and I did so for app
directory.
Directory structure
.
├── __init__.py
├── app
│ ├── __init__.py
│ ├── forms.py
│ ├── routes.py
│ └── templates
│ ├── base.html
│ ├── index.html
│ └── login.html
├── config.py
└── microblog.py
Full stacktrace
flask run
* Serving Flask app "microblog.py"
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
Usage: flask run [OPTIONS]
Error: While importing "microblog.microblog", an ImportError was raised:
Traceback (most recent call last):
File "~/anaconda3/envs/flask_python3.5.2/lib/python3.5/site-packages/flask/cli.py", line 235, in locate_app
__import__(module_name)
File "~/learning/migual_flask/microblog/microblog.py", line 1, in <module>
from app import app
ImportError: No module named 'app'
And this code worked till recently and suddenly started giving troubles. I am unable to find where this is going wrong.
Any help greatly appreciated.
Thanks.