To-Do App Final

Kategori: Python / Flask , 20 Eylül 2019 , JanFranco


To-do uygulamasında, blog uygulamasında yaptığım gibi tüm detayları yazmadım, önemli kısımları yazdım. Bu nedenle son halini paylaşıyorum. index.html dosyasının son hali:


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
        <title>To-Do App</title>
    </head>
    <body>
        <div style="margin-top: 80px;" class="container">
            <h3>To-Do List</h3>
            <hr>
            <form action="/add" method="POST">
                <div class="form-group">
                    <label for="formGroupExampleInput">Başlık</label>
                    <input type="text" class="form-control" id="formGroupExampleInput" name="title" placeholder="Başlık giriniz...">
                    <br>
                    <button type="submit" class="btn btn-danger">Gönder</button>
                </div>
            </form>
            <table class="table">
                <thead>
                    <tr>
                        <th scope="col">id</th>
                        <th scope="col">Başlık</th>
                        <th scope="col">Tamamlanma Durumu</th>
                        <th scope="col">Durumu Güncelle</th>
                        <th scope="col">Sil</th>
                    </tr>
                </thead>
                <tbody>
                    {% for todo in todos %}
                        <tr>
                            <th scope="row">{{ todo.id }}</th>
                            <td>{{ todo.title }}</td>
                            {% if todo.complete == False %}
                                <td>Tamamlanmadı</td>
                            {% else %}
                                <td>Tamamlandı</td>
                            {% endif %}
                            <td><a href="/complete/{{ todo.id }}" class="btn btn-danger">Tamamla</a></td>
                            <td><a href="/delete/{{ todo.id }}" class="btn btn-danger">Görevi Sil</a></td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    </body>
</html>
Ana dosyamızın son hali:


from flask import Flask, render_template, redirect, url_for, request
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////Users/ErenS/Desktop/flaskTo-Do/todo.db'
db = SQLAlchemy(app)

class Todo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(80))
    complete = db.Column(db.Boolean)

@app.route("/")
def index():
    todos = Todo.query.all()
    return render_template("index.html", todos = todos)

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

@app.route("/complete/<string:id>")
def complete(id):
    completed = Todo.query.filter_by(id = id).first()
    completed.complete = not completed.complete
    db.session.commit()
    return redirect(url_for("index"))

@app.route("/delete/<string:id>")
def deleteToDo(id):
    deleted = Todo.query.filter_by(id = id).first()
    db.session.delete(deleted)
    db.session.commit()
    return redirect(url_for("index"))

if __name__ == "__main__":
    db.create_all()
    app.run(debug=True)
Web sitenin son hali:

Flask To-Do App


Sonraki Yazı: User Login Control for Functions
Yorumlar

Henüz bir yorum bulunmuyor.
Yorum bırakın