1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
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()
|
cs |
'컴퓨터 > 학식_원츄_알리미_프로젝트' 카테고리의 다른 글
부산대학교 학식 메뉴 원츄 알리미 프로젝트 (0) | 2020.03.11 |
---|