Django REST framework Cheat Sheet

Django Cheat Sheet (

pip3 install djangorestframework
python3 startapp employee
Note: Make sure your sql service is running.



from django.db import models

class Employee(models.Model):
    post = models.CharField(max_length = 100)
    name = models.CharField(max_length = 100)
    salary = models.IntegerField()
    is_active = models.BooleanField(default=False)
    added_date = models.DateField(auto_created=True)
    updated_date = models.DateField(auto_now=True)

    def __str___(self):
        return self.title

to make and apply the migrations run

./ makemigrations
./ migrate


from rest_framework import serializers
from employee.models import Employee

class EmployeeSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employee
        fields = "__all__"


from django.shortcuts import render
from rest_framework.generics import ListAPIView
from rest_framework.generics import CreateAPIView
from rest_framework.generics import DestroyAPIView
from rest_framework.generics import UpdateAPIView
from employee.serializers import EmployeeSerializer
from employee.models import Employee

class ListEmpAPIView(ListAPIView):
    queryset = Employee.objects.all()
    serializer_class = EmployeeSerializer

class CreateEmpAPIView(CreateAPIView):
    queryset = Employee.objects.all()
    serializer_class = EmployeeSerializer

class UpdateEmpAPIView(UpdateAPIView):
    queryset = Employee.objects.all()
    serializer_class = EmployeeSerializer

class DeleteEmpAPIView(DestroyAPIView):
    queryset = Employee.objects.all()
    serializer_class = EmployeeSerializer


from django.urls import path
from employee import views

urlpatterns = [
    path("create/", views.CreateEmpAPIView.as_view(),name="employee_create"),


urlpatterns = [

Run the api in postman with urls

POST request : http://localhost:8000/api/v1/employee/create/ 
GET request : http://localhost:8000/api/v1/employee
UPDATE request : http://localhost:8000/api/v1/employee/update/1/ 
DELETE request : http://localhost:8000/api/v1/employee/delete/1/ 

Hosting project on InfinityFree

Create account on InfinityFree :
Note down account, MySQL and FTP details

Download FileZilla Client :

Export database table : SQL Cheat Sheet (

Go to control panel/ databases/phpmyadmin
Create database and import database table in phpmyadmin of infinityfree

Connect to infinityfree server using FTP credentials via FileZilla Client
Once connection is established upload project folder from local site to /htdocs of remote site

Change the database connection credentials (MYSQL username, password, database_name) in project as per MYSQL credentials of infinityfree.

Your project is hosted. refresh the browser and check.