From 6a5b6486ad0840c5c4414c7a842de01e43520458 Mon Sep 17 00:00:00 2001 From: Pratham Date: Fri, 15 Jul 2022 19:33:40 +0530 Subject: [PATCH] Initial Flask App --- app.py | 62 +++++++++++++++++++++++++++++++++++++++++++++ gunicorn_config.py | 2 ++ requirements.txt | Bin 0 -> 330 bytes 3 files changed, 64 insertions(+) create mode 100644 app.py create mode 100644 gunicorn_config.py create mode 100644 requirements.txt diff --git a/app.py b/app.py new file mode 100644 index 0000000..2160336 --- /dev/null +++ b/app.py @@ -0,0 +1,62 @@ +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(500), nullable=False) + date_created = db.Column(db.DateTime, default=datetime.utcnow) + + def __repr__(self) -> str: + return f"{self.sno} - {self.title}" + +@app.route('/', methods=['GET', 'POST']) +def hello_world(): + if request.method=='POST': + print('post') + title = request.form['title'] + desc = request.form['desc'] + todo = Todo(title=title, desc=desc) + todo = Todo(title="Pratham", desc="Parikh") + db.session.add(todo) + db.session.commit() + + allTodo = Todo.query.all() + return render_template('index.html', allTodo=allTodo) + +@app.route('/show') +def products(): + allTodo = Todo.query.all() + print(allTodo) + return 'this is products page' + +@app.route('/update/', 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() + return render_template('update.html', todo=todo) + +@app.route('/delete/') +def delete(sno): + todo = Todo.query.filter_by(sno=sno).first() + db.session.delete(todo) + db.session.commit() + return redirect("/") + +if __name__ == "__main__": + app.run(debug=True, port=8000) \ No newline at end of file diff --git a/gunicorn_config.py b/gunicorn_config.py new file mode 100644 index 0000000..ce8d7e7 --- /dev/null +++ b/gunicorn_config.py @@ -0,0 +1,2 @@ +bind = "0.0.0.0:8080" +workers = 2 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..94b94600427e45590dc8217673389965ad87a365 GIT binary patch literal 330 zcmZ{eyAHxI5Co@2;!{Axi9|&~LxG?`6x2}&ZxWP{0zMwtI|voXI@|J&clY_oII$<= z$Vh8QpGXtv(qSSkrT%F4{!8nzWWkKF=!_jXXKwBm^ds>xw=E5YXO&dCSzcfu-6rwG zJy+$em0F0;#g+P1JKN?DoSe$3;2<)5vm);oyFQmvsd>Xi{Zck^v&7aVa_V1mqhd|a UZrxYj<;Y!Uqh_s>HGez30B7zmfdBvi literal 0 HcmV?d00001