I'm building a web Flask- SQLAlchemy application, following step-by step from a Udemy course but as soon as I type...
from app import db
... in the terminal, I receive a "cannot import name 'db' from app" error. As you can see from the code below, I have already used 'pip' to install Flask and SQLAlchemy.
from flask import Flask, render_template, request
from flask.ext.sqlalchemy import SQLAlchemy
app= Flask(__name__)
db = SQLAlchemy(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:postgres123@localhost/height_collector'
class Data(db.Model):
__tablename__="data"
id = db.Column(db.Integer, primary_key = True)
email_ = db.Column(db.String(120), unique = True)
height_ = db.Column(db.Integer)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/success", methods = ['POST'])
def success():
if request.method=='POST':
email = request.form["email_name"]
height = request.form["height_name"]
print(email, height)
return render_template("index.html")
if __name__ == '__main__':
app.debug = True
app.run()
Could the error be further down? Still a noob so not too sure what the instructor is doing here.