Python Forum
Need help with code - thanks!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with code - thanks!
#4
looking at your python code
import os
import psycopg2
 
from flask import Flask, session, render_template
from flask_session import Session
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
 
 
app = Flask(__name__)
 
# Check for environment variable
if not os.getenv("DATABASE_URL"):
    raise RuntimeError("DATABASE_URL is not set")
 
DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
 
# Configure session to use filesystem
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)
 
# Set up database
engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))
 
 
@app.route("/")
def index():
    return "Project 1: TODO"
 
 
 
try:
    connection = psycopg2.connect(user = "***",
                                  password = "***",
                                  host = "***",
                                  port = "***",
                                  database = "***")
 
    cursor = connection.cursor()
   
 
except (Exception, psycopg2.Error) as error :
    print ("Error while connecting to PostgreSQL", error)
finally:
    #closing database connection.
        if(connection):
            cursor.close()
            connection.close()
            print("PostgreSQL connection is closed")
           
           
         
@app.route("/register", methods=["GET", "POST"])
def register():
    return render_template("register.html")
    password = request.form.get("password")
    username = request.form.get("username")
    session.clear()
    db.execute("INSERT INTO users (username, password) VALUES (:username, :password")
    db.commit()
On line 58 you always return, so the rest of the code is never executed.
By the way, remove your personal data - username, apssword, etc. from pastebin and anyway change them for security reasons
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Need help with code - thanks! - by card51shor - Jun-06-2020, 07:46 PM
RE: Need help with code - thanks! - by buran - Jun-06-2020, 07:53 PM
RE: Need help with code - thanks! - by card51shor - Jun-06-2020, 07:56 PM
RE: Need help with code - thanks! - by buran - Jun-06-2020, 08:04 PM
RE: Need help with code - thanks! - by card51shor - Jun-06-2020, 08:08 PM
RE: Need help with code - thanks! - by buran - Jun-06-2020, 08:11 PM
RE: Need help with code - thanks! - by card51shor - Jun-06-2020, 08:13 PM
RE: Need help with code - thanks! - by buran - Jun-06-2020, 08:23 PM
RE: Need help with code - thanks! - by buran - Jun-06-2020, 08:23 PM
RE: Need help with code - thanks! - by card51shor - Jun-06-2020, 08:31 PM
RE: Need help with code - thanks! - by buran - Jun-06-2020, 08:36 PM
RE: Need help with code - thanks! - by card51shor - Jun-06-2020, 08:42 PM
RE: Need help with code - thanks! - by buran - Jun-06-2020, 08:44 PM
RE: Need help with code - thanks! - by card51shor - Jun-06-2020, 09:22 PM
RE: Need help with code - thanks! - by buran - Jun-07-2020, 04:06 AM
RE: Need help with code - thanks! - by card51shor - Jun-07-2020, 05:17 AM
RE: Need help with code - thanks! - by card51shor - Jun-07-2020, 06:44 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020