├── List of Commands.txt ├── Procfile ├── app.py ├── requirements.txt └── todo.db /List of Commands.txt: -------------------------------------------------------------------------------- 1 | heroku login 2 | 3 | pip install gunicorn 4 | pip freeze requirements.txt 5 | Procfile 6 | web:gunicorn app:app 7 | 8 | git init 9 | git add . 10 | git commit -m "Initial commmit" 11 | 12 | heroku create todo-codewithharry 13 | git remote -v 14 | git push heroku master 15 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn app:app -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request, redirect 2 | from flask_sqlalchemy import SQLAlchemy 3 | from datetime import datetime 4 | 5 | app = Flask(__name__) 6 | app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///todo.db" 7 | app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False 8 | db = SQLAlchemy(app) 9 | 10 | class Todo(db.Model): 11 | sno = db.Column(db.Integer, primary_key=True) 12 | title = db.Column(db.String(200), nullable=False) 13 | desc = db.Column(db.String(500), nullable=False) 14 | date_created = db.Column(db.DateTime, default=datetime.utcnow) 15 | 16 | def __repr__(self) -> str: 17 | return f"{self.sno} - {self.title}" 18 | 19 | @app.route('/', methods=['GET', 'POST']) 20 | def hello_world(): 21 | if request.method=='POST': 22 | title = request.form['title'] 23 | desc = request.form['desc'] 24 | todo = Todo(title=title, desc=desc) 25 | db.session.add(todo) 26 | db.session.commit() 27 | 28 | allTodo = Todo.query.all() 29 | return render_template('index.html', allTodo=allTodo) 30 | 31 | @app.route('/show') 32 | def products(): 33 | allTodo = Todo.query.all() 34 | print(allTodo) 35 | return 'this is products page' 36 | 37 | @app.route('/update/', methods=['GET', 'POST']) 38 | def update(sno): 39 | if request.method=='POST': 40 | title = request.form['title'] 41 | desc = request.form['desc'] 42 | todo = Todo.query.filter_by(sno=sno).first() 43 | todo.title = title 44 | todo.desc = desc 45 | db.session.add(todo) 46 | db.session.commit() 47 | return redirect("/") 48 | 49 | todo = Todo.query.filter_by(sno=sno).first() 50 | return render_template('update.html', todo=todo) 51 | 52 | @app.route('/delete/') 53 | def delete(sno): 54 | todo = Todo.query.filter_by(sno=sno).first() 55 | db.session.delete(todo) 56 | db.session.commit() 57 | return redirect("/") 58 | 59 | if __name__ == "__main__": 60 | app.run(debug=True, port=8000) -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Warlord27/Flask/75f6eb24c3bf2cb72137e91449c4646229768d8e/requirements.txt -------------------------------------------------------------------------------- /todo.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Warlord27/Flask/75f6eb24c3bf2cb72137e91449c4646229768d8e/todo.db --------------------------------------------------------------------------------