A RESTful API for managing ToDo tasks using Django and Django REST Framework (DRF).
- CRUD operations for ToDo tasks
- RESTful endpoints with Django REST Framework
- CORS headers enabled for cross-origin requests
- Browsable API interface
- Filtering support (optional enhancement)
- Python 3.9+
- Pipenv (for virtual environment management)
- Django
- Django REST Framework
- Django CORS Headers
-
Clone the repository
git clone https://github.com/ZakariaElkhadir/Django-ToDo.git cd Django-ToDo -
Set up virtual environment and install dependencies
pipenv install pipenv shell
-
Run migrations
python manage.py migrate
-
Create a superuser (optional)
python manage.py createsuperuser
-
Run the development server
python manage.py runserver
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/todos/ |
List all todos |
| POST | /api/todos/ |
Create a new todo |
| GET | /api/todos/{id}/ |
Retrieve a specific todo |
| PUT | /api/todos/{id}/ |
Update a specific todo |
| PATCH | /api/todos/{id}/ |
Partially update a specific todo |
| DELETE | /api/todos/{id}/ |
Delete a specific todo |
- Download the Postman Collection (optional).
- Import it into Postman using
File > Import.
Base URL: http://localhost:8000/api/todos/
- Set request method: POST
- Set headers:
Content-Type: application/json - Request body (raw JSON):
{ "title": "Buy groceries", "description": "Milk, eggs, bread", "completed": false }
- Set request method: GET
- Send request to:
http://localhost:8000/api/todos/
- Set request method: PUT
- Use URL format:
http://localhost:8000/api/todos/1/(replace1with actual ID) - Request body:
{ "title": "Updated title", "completed": true }
- Set request method: DELETE
- Use URL format:
http://localhost:8000/api/todos/1/
curl -X POST -H "Content-Type: application/json" -d '{"title":"New Task"}' http://localhost:8000/api/todos/curl http://localhost:8000/api/todos/curl -X PUT -H "Content-Type: application/json" -d '{"title":"Updated Task"}' http://localhost:8000/api/todos/1/Access the API through your web browser at:
http://localhost:8000/api/todos/
# settings.py
REST_FRAMEWORK = {
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
}- Filter using:
/api/todos/?completed=true
# settings.py
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10
}Use djangorestframework-simplejwt for secure authentication.