Skip to content

Django-based application for managing tasks and to-do lists

Comprehensive Learning Hub: A versatile educational platform, encompassing a wide range of subjects, from computer science and programming to school education, upskilling, commerce, software tools, competitive exams, and beyond, designed to inspire learners in all domains.

Comprehensive Learning Hub: Our educational platform encompasses a vast range of subjects,...
Comprehensive Learning Hub: Our educational platform encompasses a vast range of subjects, including computer science and programming, traditional school curriculum, professional development, commerce, software tools, competitive exam preparation, and more, equipping learners in various domains.

Django-based application for managing tasks and to-do lists

Next Article Creating a Simple ToDo App with Django

Author: ItsVinayak

Categories: Python, Web Technologies, HTML, Python Django, Django-Projects, python

Ready to build a ToDo app using Django? This guide covers setting up the project, creating a ToDo model, designing forms, views, and templates, and implementing core functionalities like adding, viewing, and deleting tasks. Let's dive in!

Basic setup

  1. Create a virtual environment:

  1. Install the packages:

Step 1: Create a Django Project

Start a new Django project named :

Step 2: Navigate to the project directory

Step 3: Create a Django App

Create an app named :

The directory structure should look like this:

Step 4: Add the todo App to Settings

In , add to the list:

Step 5: Configure URLs

Edit to include the app views:

```pythonfrom django.contrib import adminfrom django.urls import path, include

urlpatterns = [ path('admin/', admin.site.urls), path('', include('todo.urls')),]```

Step 6: Define the ToDo Model

Edit to define the Todo model:

```pythonfrom django.db import models

class Todo(models.Model): title = models.CharField(max_length=100) description = models.TextField() created_at = models.DateTimeField(auto_now_add=True)

```

Step 7: Create Views

Edit :

```pythonfrom django.shortcuts import render, redirectfrom .models import Todofrom .forms import TodoForm

def index(request): todos = Todo.objects.all() form = TodoForm() if request.method == 'POST': form = TodoForm(request.POST) if form.is_valid(): form.save() return redirect('index')

def remove(request, pk): todo = Todo.objects.get(pk=pk) todo.delete() return redirect('index')```

Step 8: Create a Form

In , add the following:

```pythonfrom django import formsfrom .models import Todo

class TodoForm(forms.ModelForm): class Meta: model = Todo fields = ('title', 'description')```

Step 9: Register the Model with Admin

Edit to register the Todo model:

```pythonfrom django.contrib import adminfrom .models import Todo

admin.site.register(Todo)```

Step 10: Create the Template

Create the folder and add :

```html{% load crispy_forms_tags %}

  • {% for todo in todos %}
  • {{ todo.title }} - {{ todo.description }}
  • Delete
  • {% endfor %}

```

Step 11: Apply Migrations

Create and apply migrations to set up the database schema:

Step 12: Run the Development Server

Start the Django development server:

Open your web browser and go to to see your ToDo app in action!

In the process of building the ToDo app, technology used includes Django, Python Django, Python, HTML, and Django-Crispy-Forms. These pieces of technology are instrumental in creating the project's structure, managing the database, designing forms, and enhancing user interface elements.

Read also:

    Latest