ModuleNotFoundError: No module named 'app' w/ Flask & SqlAlchemy

Viewed 21

When I try to use my command prompt to open a SQLalchemy database, I am getting an error that says that ModeuleNotFoundError: No Module named 'app'. Where do you think I went wrong with my code?

I have my code below but only the top portion and the final 3 lines. Thanks to those that give any feedback.

File name: Webpage.py

from datetime import datetime 
from flask import Flask, render_template, url_for, flash, 
redirect 
import sqlalchemy
from flask_sqlalchemy import SQLAlchemy
from forms import RegistrationForm, LoginForm
app = Flask(__name__, template_folder='template')
from flask import app
from app import db           <------ Error occurs here 

................
................
................
................

if __name__ == '__main__':
    app.run(debug=True)
    app.run(host="0.0.0.0", port=8080, threaded=True)
1 Answers

Instead of importing it from app you should create it and attach it to your application:

app = Flask(__name__)
db = SQLAlchemy(app)

Also you should not have two app.run lines, you can add debug=True in your second line

Related