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.
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)
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.