-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6a5b648
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/<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() | ||
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("/") | ||
|
||
if __name__ == "__main__": | ||
app.run(debug=True, port=8000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bind = "0.0.0.0:8080" | ||
workers = 2 |
Binary file not shown.