I am trying to get my login page working with blueprints. Before I separated my python package into separate packages, the app was successfully running with just app.py. However, now I am trying to make it more modular, I am having trouble running the app and it does not let me import the blueprint
I created.
My file structure is like this:
myapp/
run.py
myapp/
__init.py__
app.py
models.py
...
Here is my run.py
:
from myapp import app
app.run(host= '0.0.0.0', debug=True)
I am initializing my blueprint in app.py
like this:
....
from flask import Blueprint
bp = Blueprint('bp', __name__)
@bp.route('/')
@bp.route('/home')
....
I am calling it from __init.py__
like this:
app = Flask(__name__)
....
app.config...
app.config...
app.config...
....
from . import bp # line 35
app.register_blueprint(bp)
However, no matter what I change the import to, it keeps complaining that it cannot import
# python3 run.py
Traceback (most recent call last):
File "run.py", line 1, in <module>
from usb import app
File "/my/path/to/myapp/myapp/__init__.py", line 35, in <module>
from . import bp
ImportError: cannot import name 'bp'
I even tried changing from . import bp
to from myapp.app import bp
, and then it throws a different error AttributeError: module 'myapp.app' has no attribute 'register_blueprint'
Here is the full error:
Traceback (most recent call last):
File "run.py", line 1, in <module>
from myapp import app
File "/my/path/to/myapp/myapp/__init__.py", line 33, in <module>
app.register_blueprint(bp)
AttributeError: module 'myapp.app' has no attribute 'register_blueprint'
Does anyone know what I am doing wrong here?