-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
54 lines (37 loc) · 1.18 KB
/
app.py
File metadata and controls
54 lines (37 loc) · 1.18 KB
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
52
53
54
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 11 19:01:55 2022
@author: arupb
"""
from flask import Flask, render_template, request
from flask_sqlalchemy import SQLAlchemy
from config import SQLALCHEMY_DATABASE_URI, SECRET_KEY
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.secret_key = SECRET_KEY
db = SQLAlchemy(app)
class People(db.Model):
id = db.Column(db.Integer, primary_key=True)
pname = db.Column(db.String(80), unique=True, nullable=False)
color = db.Column(db.String(120), nullable=False)
def __init__(self, pname, color):
self.pname = pname
self.color = color
@app.route('/')
def home():
return '<a href="/addperson"><button> Click here </button></a>'
@app.route("/addperson")
def addperson():
return render_template("index.html")
@app.route("/personadd", methods=['POST'])
def personadd():
pname = request.form["pname"]
color = request.form["color"]
entry = People(pname, color)
db.session.add(entry)
db.session.commit()
return render_template("index.html")
if __name__ == '__main__':
db.create_all()
app.run()