I am having issues linking my flask program to Postgre SQL
import os
from flask import Flask, session
from flask_session import Session
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from flask import Flask, render_template, request
app = Flask(__name__)
# Check for environment variable
if not os.getenv("DATABASE_URL"):
raise RuntimeError("DATABASE_URL is not set")
# Configure session to use filesystem
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
# Set up database
engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))
@app.route("/")
def index():
return render_template("index.html")
@app.route("/register.html",methods=['GET','POST'])
def register():
return render_template("register.html")
if request.method=='POST':
name=request.form['username']
password=request.form['password']
connection = mysql.get_db()
cursor = connection.cursor()
query="INSERT INTO 'User Details'(username,password) VALUES(%s,%s)"
cursor.execute(query,(username,password))
connection.commit()
@app.route("/login.html")
def login():
return render_template("login.html")
Register.html
<html>
<head>
<title>Project1</title>
</head>
<form method="POST">
<input type="username" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<input type="submit" value="Register">
</form>
</html>
I have already specified the DATABASE_URl when setting up with the credentials given by Heroku. I cannot manage to store the username and password into the database. The register.html page contains a form with username input field and password input field. Help will be appreciated.
Thanks