Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

FROM python:3.8.2

WORKDIR /app

COPY . /app

RUN pip install -r requirements.txt

EXPOSE 5000

CMD ["python","app.py"]
30 changes: 14 additions & 16 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,46 @@

app = Flask(__name__)

# /// = relative path, //// = absolute path
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)


class Todo(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100))
complete = db.Column(db.Boolean)
title = db.Column(db.String(100), nullable=False)
complete = db.Column(db.Boolean, default=False)

with app.app_context():
db.create_all()

@app.route("/")
def home():
todo_list = Todo.query.all()
return render_template("base.html", todo_list=todo_list)


@app.route("/add", methods=["POST"])
def add():
title = request.form.get("title")
new_todo = Todo(title=title, complete=False)
db.session.add(new_todo)
db.session.commit()
if title:
new_todo = Todo(title=title, complete=False)
db.session.add(new_todo)
db.session.commit()
return redirect(url_for("home"))


@app.route("/update/<int:todo_id>")
@app.route("/update/<int:todo_id>", methods=["POST"])
def update(todo_id):
todo = Todo.query.filter_by(id=todo_id).first()
todo = Todo.query.get_or_404(todo_id)
todo.complete = not todo.complete
db.session.commit()
return redirect(url_for("home"))


@app.route("/delete/<int:todo_id>")
@app.route("/delete/<int:todo_id>", methods=["POST"])
def delete(todo_id):
todo = Todo.query.filter_by(id=todo_id).first()
todo = Todo.query.get_or_404(todo_id)
db.session.delete(todo)
db.session.commit()
return redirect(url_for("home"))

if __name__ == "__main__":
db.create_all()
app.run(debug=True)
app.run(host="0.0.0.0", port=5000, debug=True)

6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#This Is Create For install Required Libraries Efficiently

Flask

Flask-SQLAlchemy