Build REST API using DRF

pip install djangorestframework
django-admin startproject djangoCore
cd djangoCore
python manage.py startapp myApp
INSTALLED_APPS = [
..................
'rest_framework'
'myApp'
..................
]
class StudentRecord(models.Model):
name=models.CharField(max_length=200)
student_id=models.CharField(max_length=100)
department=models.CharField(max_length=100)
completed_credit=models.IntegerField()
blood_group=models.CharField(max_length=10)
phone_number=models.CharField(max_length=20)
python manage.py makemigrations myApp
python manage.py migrate
from rest_framework.serializers import ModelSerializer
from myApp.models import StudentRecord

class StudentSerializers(ModelSerializer):
class Meta:
model = StudentRecord
fields = '__all__'
from rest_framework.viewsets import ModelViewSet
from myApp.models import StudentRecord
from myApp.serializers import StudentSerializers

class StudentView(ModelViewSet):
serializer_class = StudentSerializers
queryset = StudentRecord.objects.all()
from django.urls import path, include
from rest_framework.routers import DefaultRouter

from myApp.views import StudentView

router = DefaultRouter()
router.register('student', StudentView, basename='student')
urlpatterns = [
path('', include(router.urls))
]

--

--

--

https://sites.google.com/site/codingbynasir

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

6 metrics for HTTP file extraction

15 Best No-Code Tools that you can use to build your next startup

Explained: data governance vs data management

Part 2: Etymology of Variables

Substrate Programming Starter Guide

Setup Google Login in your Cordova/Phonegap App

Retry Mechanism and Delay Queues in Apache Kafka

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nasir

Nasir

https://sites.google.com/site/codingbynasir

More from Medium

Get start Django project, and its files and directories structure

Handle MEDIA files in production — Django

floppy disks and Django media

Implementing a REST API with Django REST framework

An Introduction to GraphQL in Django