An open API service indexing awesome lists of open source software.

https://github.com/billy-enrizky/task-manager

Task Manager Using Flask
https://github.com/billy-enrizky/task-manager

flask

Last synced: 7 months ago
JSON representation

Task Manager Using Flask

Awesome Lists containing this project

README

          

# Create Task Manager Using Flask

This is a guide on how to create a Task Manager web application using Flask, a Python web framework. The Task Manager allows users to add, edit, and delete tasks with a title and description.

## Prerequisites

Before getting started, make sure you have the following installed:

- Python (version 3.6 or later)
- Flask (install using `pip install flask`)

## Project Setup

1. Create a new directory for your project and navigate to it.
2. Initialize a new virtual environment:
```shell
python -m venv venv
```
3. Activate the virtual environment:
- On Windows:
```shell
venv\Scripts\activate
```
- On macOS/Linux:
```shell
source venv/bin/activate
```
4. Create a new Python file called `app.py` for our Flask application.

## Setting Up the Flask Application

1. Open `app.py` and import the necessary modules:
```python
from flask import Flask, render_template, request, redirect, url_for
from datetime import datetime
```
2. Create an instance of the Flask application:
```python
app = Flask(__name__)
```
3. Define a route for the home page:
```python
@app.route('/')
def index():
return render_template('index.html')
```
4. Add a route to handle the form submission for adding a new task:
```python
@app.route('/add', methods=['POST'])
def add_task():
title = request.form['title']
desc = request.form['desc']
date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# TODO: Save the task to a database or any other storage
return redirect(url_for('index'))
```
5. Add a route to render the form for adding a new task:
```python
@app.route('/add')
def show_add_form():
return render_template('add.html')
```
6. Add a route to handle the form submission for editing a task:
```python
@app.route('/edit/', methods=['POST'])
def edit_task(task_id):
title = request.form['title']
desc = request.form['desc']
# TODO: Update the task with the given task_id in the database or storage
return redirect(url_for('index'))
```
7. Add a route to render the form for editing a task:
```python
@app.route('/edit/')
def show_edit_form(task_id):
# TODO: Retrieve the task with the given task_id from the database or storage
# Pass the task data to the template
return render_template('edit.html', task=task)
```
8. Add a route to handle deleting a task:
```python
@app.route('/delete/')
def delete_task(task_id):
# TODO: Delete the task with the given task_id from the database or storage
return redirect(url_for('index'))
```
9. Run the Flask application:
```shell
flask run
```

## HTML Templates

Create the following HTML templates in a new directory called `templates`:

1. `index.html`:
```html
{% extends "base.html" %}

{% block main %}

{% endblock %}
```

2. `add.html`:
```html
{% extends "base.html" %}

{% block main %}

Add Task



Title:



Description:





{% endblock %}
```

3. `edit.html`:
```html
{% extends "base.html" %}

{% block main %}

Edit Task



Title:



Description:
{{ task.desc }}




{% endblock %}
```

4. `base.html`:
```html






Task Manager








{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}

{{ message }}

{% endfor %}
{% endif %}
{% endwith %}


Task Manager




{% block main %}{% endblock %}






```

## Conclusion

Congratulations! You have created a Task Manager web application using Flask. The application allows users to add, edit, and delete tasks. You can further enhance the application by connecting it to a database, implementing authentication, and adding additional features as per your requirements.

Remember to always follow best practices for web development, including validating user input, securing sensitive data, and properly handling errors. Enjoy building more features on top of this foundation!