Django & Django Rest Framework (DRF)

Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. DRF is used to build robust and scalable RESTful APIs.

Setup and Integration

  1. Install Django and DRF

pip install django djangorestframework
  1. Create a Django Project and App

django-admin startproject ewalletly
cd ewalletly
python manage.py startapp api
  1. Define Models, Serializers, and Views:

    1. models.py:

from django.db import models

class Wallet(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    balance = models.DecimalField(max_digits=10, decimal_places=2)
    currency = models.CharField(max_length=3)
  1. serializers.py:

from rest_framework import serializers
from .models import Wallet

class WalletSerializer(serializers.ModelSerializer):
    class Meta:
        model = Wallet
        fields = '__all__'
  1. views.py

  1. urls.py

Last updated