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:

Prerequisites
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:

flask-crud-app/
    app.py
    templates/
        index.html
    database.db

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

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)

@app.route('/')
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)
    db.session.add(new_task)
    db.session.commit()
    return redirect('/')

@app.route('/update/<int:id>')
def update(id):
    task = Task.query.get(id)
    task.completed = not task.completed
    db.session.commit()
    return redirect('/')

@app.route('/delete/<int:id>')
def delete(id):
    task = Task.query.get(id)
    db.session.delete(task)
    db.session.commit()
    return redirect('/')

if __name__ == '__main__':
    db.create_all()
    app.run(debug=True)

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">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Task List</title>
</head>
<body>
    <h1>Task List</h1>
    <form method="POST" action="/add">
        <input type="text" name="content" required>
        <button type="submit">Add Task</button>
    </form>
    <ul>
        {% for task in tasks %}
            <li>
                {{ task.content }}
                <a href="/update/{{ task.id }}">Complete</a>
                <a href="/delete/{{ task.id }}">Delete</a>
            </li>
        {% endfor %}
    </ul>
</body>
</html>

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

python app.py

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.