Python

Build a REST API with Django in 30 Minutes — Beginner to Deployed

Akash Verma March 2026 9 min read

Build, authenticate, and deploy a real Django REST API. Working code at every step — from model to live URL.

What You Will Build

A working REST API with user registration, JWT authentication, and a protected data endpoint. By the end you will have a live URL you can hit from Postman or a mobile app.

Setup

pip install django djangorestframework djangorestframework-simplejwt
django-admin startproject myapi
cd myapi
python manage.py startapp users

The Model

# users/models.py
from django.db import models
class Profile(models.Model):
    user = models.OneToOneField('auth.User', on_delete=models.CASCADE)
    bio = models.TextField(blank=True)
    created_at = models.DateTimeField(auto_now_add=True)

The Serializer

class RegisterSerializer(serializers.ModelSerializer):
    password = serializers.CharField(write_only=True, min_length=8)
    class Meta:
        model = User
        fields = ['username', 'email', 'password']
    def create(self, validated_data):
        return User.objects.create_user(**validated_data)

Views

class RegisterView(generics.CreateAPIView):
    serializer_class = RegisterSerializer
    permission_classes = [permissions.AllowAny]

class ProfileView(generics.RetrieveAPIView):
    permission_classes = [permissions.IsAuthenticated]
    def get(self, request):
        return Response({'username': request.user.username, 'email': request.user.email})

URLs

urlpatterns = [
    path('api/register/', RegisterView.as_view()),
    path('api/login/', TokenObtainPairView.as_view()),
    path('api/token/refresh/', TokenRefreshView.as_view()),
    path('api/profile/', ProfileView.as_view()),
]

Deploying

Fastest free option: Railway.app or Render.com. Add gunicorn, set DEBUG=False, configure ALLOWED_HOSTS, push to GitHub. The platform deploys automatically.

What Comes Next

This is the foundation. Real apps add: pagination, filtering with django-filter, file uploads with S3, Celery for background tasks, Redis caching. These are modules in the Python course at Cloudemy Edge, Lucknow — built on exactly this structure.

Ready to build this for real? This is what we teach hands-on at Cloudemy Edge, Lucknow — real code, real projects, real career outcomes.
Python Training in Lucknow →

Ready to stop reading and start building?

Apply for Python Training →