from flask import Flask, render_template import psycopg2 app = Flask(__name__) # Connect to the database conn = psycopg2.connect(database="testdb", user="sql-ledger", password="a123s", host="localhost", port="5432") @app.route('/') def index(): # Connect to the database conn = psycopg2.connect(database="testdb", user="sql-ledger", password="a123s", host="localhost", port="5432") # create a cursor cur = conn.cursor() # Select all products from the table cur.execute("Select distinct p.partnumber as Part, p.description, p.unit, p.listprice, p.onhand, p.image from parts p where p.toolnumber = 'yes'") # Fetch the data data = cur.fetchall() # close the cursor and connection cur.close() conn.close() return render_template('index.html', data=data) if __name__ == '__main__': app.run(host='0.0.0.0', debug=True)