from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import os
from werkzeug.security import generate_password_hash, check_password_hash
from datetime import datetime
import pandas as pd
#create app and db
app = Flask(__name__)
app.config['SECRET_KEY'] = 'dlfldhsjfk'
print(os.path.join(os.path.abspath(os.path.dirname(__file__)), "practice.db"))
app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://postgres:password@localhost:5432"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class Users(db.Model):
__table_name__ = "users"
pk = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
username = db.Column(db.String(100), nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
password = db.Column(db.String(100), nullable=False)
def __init__(self, username, email, password, **kwargs):
self.username = username
self.email = email
self.password = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.password, password)
def __repr__(self):
return f"<User('{self.pk}', '{self.username}', '{self.email}')>"
@app.route("/")
def hello():
db.create_all()
return "db init finish!"
@app.route("/<name>-<email>-<password>")
def set_person(name, email, password):
user = Users(username=name, email=email, password=password)
db.session.add(user)
db.session.commit()
pd.read_sql("select * from users", db)
print(pd.head())
return f"User : {name}, {email}, {password} is added"
app.run()