To-Do List in Python: Step-by-Step Guide - DJC
A To-Do List is one of the most classic projects to learn programming.
With this project in Python, you will not only practice the basics of the language, but also move toward a more professional level by creating web applications with Django.
In this guide, you will learn how to:
- Create a simple To-Do List in Python from the console.
- Improve the application using files or databases to store tasks.
- Build a To-Do List with Django, ready to be deployed on the web.
Why a To-Do List in Python?
Building a to-do list in Python is an ideal project because it combines simplicity with scalability:
- It lets you practice lists, functions, and control structures.
- You learn how to save and load data.
- You discover how to turn a basic idea into a web project with Django, one of the most popular Python frameworks.
In addition, it’s a project you can customize and showcase in your programmer portfolio.
1. Basic To-Do List in Console
We’ll start with a minimal version that runs in the terminal.
At this level, you will learn how to:
- Add tasks.
- Mark tasks as completed.
- Delete tasks.
- Display the updated list.
# to_do_list.py
tasks = []
def show_tasks():
print("\n--- Tasks ---")
for i, task in enumerate(tasks, 1):
print(f"{i}. {task}")
while True:
print("\n1. Add task")
print("2. View tasks")
print("3. Exit")
option = input("Choose an option: ")
if option == "1":
new_task = input("Write the task: ")
tasks.append(new_task)
elif option == "2":
show_tasks()
elif option == "3":
break
else:
print("Invalid option")
This example is simple, but it serves as the foundation for further development.
2. Saving Tasks to a File
The next step is to persist the information, meaning saving tasks even after closing the program.
This can be achieved with a .txt
file or even JSON.
Here you will practice file reading and writing in Python, which is essential in any real project.
3. To-Do List with a Graphical Interface
We can improve the user experience by using libraries like Tkinter or PyQt. This will allow you to display tasks in a window and add buttons to interact with them.
That way, your to-do list is no longer just a console program but becomes a desktop application in Python.
4. To-Do List with Django (Web Application)
The most advanced step is building a To-Do List on the web using Django. With this approach you will learn how to:
- Create a Django project.
- Define a Task model in the database.
- Use forms to add, edit, and delete tasks.
- Build HTML templates with Django Templates.
- Deploy your application on a server (e.g., Railway, Render, Heroku, or VPS).
A project like this is perfect for your professional portfolio, as it demonstrates your ability to build complete applications.
The To-Do List in Python is a versatile project suitable for all levels:
- If you are just starting out, you can build it in the console.
- If you want to progress, add persistence and a graphical interface.
- And if you are looking for a bigger challenge, turn it into a web application with Django.
This way, you not only practice programming in Python but also learn how to develop real, production-ready software.
Coming Soon
The to-do list project is still under development, so we’ll be adding more content in the coming days.
Detailed tutorials for each version of the To-Do List in Python, with step-by-step code.
Stay tuned to this section to follow the development process.