Django Rest API Framework

  • By Sagar Gade
  • June 22, 2024
  • Django
Django Rest API Framework

Django Rest API Framework

Django Rest API Framework is a powerful and flexible toolkit for building Web APIs in Django. It simplifies the creation of well-documented APIs. 

 

How to install Django rest framework  

pip install django djangorestframework 

 

How to create a project in Django. 

django-admin startproject myproject 

cd myproject 

 

How to create a Project application in Django. 

python manage.py startapp myapp 

 

How to create models.py file 

from django.db import models 

class Item_details(models.Model): 

name = models.CharField(max_length=100) 

description = models.TextField() 

def __str__(self): 

return self.name 

 

For Free, Demo classes Call: 020-71177359

Registration Link: Django Classes in Pune!

 

Run migrations to create the database tables 

python manage.py makemigrations 

python manage.py migrate 

 

How to Create Serilizers Files in Django-Python 

from rest_framework import serializers 

from .models import Item 

➔ 

class ItemSerializer(serializers.ModelSerializer): 

class Meta: 

model = Item 

fields = [‘id’, ‘name’, ‘description’] 

 

How to create views using Django DRF  

from rest_framework import serializers 

from .models import Item 

➔ 

class ItemSerializer(serializers.ModelSerializer): 

class Meta:

model = Item 

fields = [‘id’, ‘name’, ‘description’] 

 

How to run server  

python manage.py runserver 

This guide provides a basic setup for creating a Django REST API using the Django Rest Framework. You can extend this by adding more features like advanced permissions, filtering, search, and custom actions._

 

Do visit our channel to learn More: Click Here

 

Author:-

Sagar Gade

Call the Trainer and Book your free demo Class for Django Call now!!!

| SevenMentor Pvt Ltd.

© Copyright 2021 | SevenMentor Pvt Ltd

Submit Comment

Your email address will not be published. Required fields are marked *

*
*