NameError: name 'SQLALCHEMY_DATABASE_URI' is not defined

Hello good people,

I am currently getting this error whenever I try to run my application with python3 app.py. I have tried looking for solutions from StackOverflow but I have found none.
Can someone please help me to suggest a fix to this error? Here is the code in my ## app.py file:

from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy

app = Flask(name)
app.config[SQLALCHEMY_DATABASE_URI] = 'postgres://postgres:147852@localhost:5432/todoapp’
db = SQLAlchemy(app)

class Todo(db.Model):
** tablename = ‘todos’**
** id = db.Column(db.Integer, primary_key = True)**
** description = db.Column(db.String(), nullable=False)**

** def repr(self):**
** return f’<Todo {self.id} {self.descriprtion}>’**

db.create_all()

@app.route(’/’)

def index():
** return render_template(‘index.html’, data = Todo.query.all())**

if name == ‘main’:
** app.run(host=“0.0.0.0”, port=3000)**

I was getting the same error, I wrote it as a string inside the app.config and it worked.
Like this:
app.config[’ SQLALCHEMY_DATABASE_URI ’ ] = 'postgres://postgres:147852@localhost:5432/todoapp’

1 Like