-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
99 lines (87 loc) · 3.27 KB
/
app.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
MIT License
Copyright (c) 2021 Aditya Bhushan(TierGamerpy)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from flask import Flask,render_template,request,redirect
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///todo.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class Todo(db.Model):
sno = db.Column(db.Integer,primary_key=True)
title = db.Column(db.String(200),nullable=False)
desc = db.Column(db.String,nullable=False)
date_created = db.Column(db.DateTime,default=datetime.utcnow())
def __repr__(self) -> str:
return f"{self.sno} - {self.title}"
# @app.route('/')
# def hello_world():
# return 'Hello, World!'
# rendering html
@app.route('/',methods=['GET','POST'])
def hello_world():
if request.method=='POST':
title = request.form['title']
desc = request.form['desc']
todo = Todo(title = title,desc = desc)
db.session.add(todo)
db.session.commit()
allTodo = Todo.query.all()
# print(allTodo)
return render_template('index.html',allTodo = allTodo)
# @app.route('/products')
# def products():
# allTodo = Todo.query.all()
# # print(allTodo)
# return 'This Is Products Page'
@app.route('/update/<int:sno>',methods=['GET','POST'])
def update(sno):
if request.method=='POST':
title = request.form['title']
desc = request.form['desc']
todo = Todo.query.filter_by(sno=sno).first()
todo.title = title
todo.desc = desc
db.session.add(todo)
db.session.commit()
return redirect("/")
todo = Todo.query.filter_by(sno=sno).first()
# print(allTodo)
return render_template('update.html',todo = todo)
@app.route('/delete/<int:sno>')
def delete(sno):
todo = Todo.query.filter_by(sno=sno).first()
db.session.delete(todo)
db.session.commit()
return redirect("/")
@app.route("/about")
def about():
return render_template('about.html')
@app.errorhandler(404)
def not_valid_url(e):
return render_template('404.html')
@app.errorhandler(403)
def invalid_acces(e):
return render_template('403.html')
@app.errorhandler(500)
def internal_error(e):
return render_template('500.html')
if __name__=="__main__":
app.run(debug=True,port=8000)