Creating a CRUD (Create, Read, Update, Delete) application in Flask is a common task for web developers. In this tutorial, we’ll build a simple CRUD app for managing a list of tasks. In the next tutorial, we’ll deploy it on the cloud. So stay tuned for the next one too! We’ll use Flask for the web framework and SQLite as the database. Here’s a step-by-step guide:

Make sure you have Python and Flask installed on your system. You can install Flask using pip:

pip install Flask

Step 1: Setting Up the Project

Create a new directory for your project and navigate to it in your terminal:

mkdir flask-crud-app
cd flask-crud-app

Step 2: Project Structure

Inside your project directory, create the following structure:


Step 3: Writing the Flask Application
Now, let’s create the Flask application in

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

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
db = SQLAlchemy(app)

class Task(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.String(200), nullable=False)
    completed = db.Column(db.Boolean, default=False)

def index():
    tasks = Task.query.all()
    return render_template('index.html', tasks=tasks)

@app.route('/add', methods=['POST'])
def add():
    content = request.form['content']
    new_task = Task(content=content)
    return redirect('/')

def update(id):
    task = Task.query.get(id)
    task.completed = not task.completed
    return redirect('/')

def delete(id):
    task = Task.query.get(id)
    return redirect('/')

if __name__ == '__main__':

Step 4: Creating HTML Templates
Create an HTML template for rendering the tasks. In the templates folder, create index.html:

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Task List</title>
    <h1>Task List</h1>
    <form method="POST" action="/add">
        <input type="text" name="content" required>
        <button type="submit">Add Task</button>
        {% for task in tasks %}
                {{ task.content }}
                <a href="/update/{{ }}">Complete</a>
                <a href="/delete/{{ }}">Delete</a>
        {% endfor %}

Step 5: Running the Application
Now, you can run your Flask CRUD app:


Visit http://localhost:5000 in your web browser to use your CRUD app. You can add, complete, and delete tasks from the list.

This is a simple example of a CRUD app using Flask. You can expand and customize it to fit your specific needs or use it as a starting point for more complex web applications.