Django REST Framework Simple Todo API - Djangorestframework Typing CST Test
Loading…
Django REST Framework Simple Todo API — Djangorestframework Code
Demonstrates a simple DRF API with a Todo model, serializer, and viewset for CRUD operations.
# models.py
from django.db import models
class Todo(models.Model):
title = models.CharField(max_length=255)
completed = models.BooleanField(default=False)
# serializers.py
from rest_framework import serializers
from .models import Todo
class TodoSerializer(serializers.ModelSerializer):
class Meta:
model = Todo
fields = ['id', 'title', 'completed']
# views.py
from rest_framework import viewsets
from .models import Todo
from .serializers import TodoSerializer
class TodoViewSet(viewsets.ModelViewSet):
queryset = Todo.objects.all()
serializer_class = TodoSerializer
# urls.py
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import TodoViewSet
router = DefaultRouter()
router.register(r'todos', TodoViewSet)
urlpatterns = [
path('', include(router.urls)),
]Djangorestframework Language Guide
Django REST Framework (DRF) is a powerful and flexible toolkit for building Web APIs in Python. It extends Django to make API development fast, secure, and maintainable.
Primary Use Cases
- ▸RESTful APIs for web applications
- ▸Mobile app backends
- ▸Third-party integrations and microservices
- ▸Prototyping and MVP development
- ▸Data-driven applications with complex querying
Notable Features
- ▸Serialization and deserialization of complex data
- ▸Browsable API for easy testing and exploration
- ▸Authentication and permission handling
- ▸Filtering, pagination, and throttling
- ▸Class-based views with mixins for rapid development
Origin & Creator
Created by Tom Christie in 2011 and maintained by the Django REST Framework community.
Industrial Note
DRF is widely used in building scalable web APIs, mobile backends, and integrations where Python/Django expertise is preferred.