Building a ToDo List App with Flask and MySQL
Inspiration
The idea for this project came from the need for a simple yet functional ToDo list application. I wanted to create a basic application using Flask and MySQL to understand how these technologies work together.
What I learned
- Flask: I learned how to create routes, render HTML templates, and handle form submissions using Flask.
- MySQL with Python: I learned how to connect to a MySQL database using Python, execute SQL queries, and handle database operations.
- Form Handling with WTForms: I learned how to use WTForms to create forms, perform form validation, and render forms in Flask templates.
- Error Handling: I learned the importance of error handling, especially when dealing with database operations.
How I built the project
- Setting up Flask: I started by setting up a Flask application with routes for the home page, adding and editing ToDo items, and deleting ToDo items.
- Creating MySQL database: I created a MySQL database named "flask" and a table named "todo" with a single column "activity".
- Creating WTForms: I created two WTForms classes, TodoForm for adding ToDo items and EditTodoForm for editing ToDo items.
- Rendering templates: I created HTML templates for the home page (todo.html) and the edit ToDo page (edit_todo.html).
- Writing route functions: I implemented route functions for adding, editing, and deleting ToDo items, handling form submissions, and rendering templates. Error Handling: I added error handling to handle exceptions that may occur during database operations.
Challenges I faced
- Database Connection: Figuring out how to properly establish and close a connection to the MySQL database was a challenge.
- Error Handling: Implementing error handling for database operations was tricky, especially handling different types of MySQL errors.
- Form Validation: Understanding how to use WTForms for form validation and rendering forms in Flask templates took some time to grasp.
Conclusion
Building this project was a great learning experience. I now have a better understanding of how to create a web application using Flask and integrate it with a MySQL
Note:
video demo link is given under try it out section, please click the dropbox link to check it out.
Languages and Frameworks used:
Log in or sign up for Devpost to join the conversation.