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.