Skip to content

Instantly share code, notes, and snippets.

@pkbhowmick
Created September 29, 2024 09:03
Show Gist options
  • Save pkbhowmick/a5b4c9d85b5ff529f65ef24a39ca576e to your computer and use it in GitHub Desktop.
Save pkbhowmick/a5b4c9d85b5ff529f65ef24a39ca576e to your computer and use it in GitHub Desktop.
from django.shortcuts import render
from django.http import HttpResponse, Http404
from rest_framework.views import APIView
from .serializers import ProductSerializers
from rest_framework.response import Response
from rest_framework import status
from .models import Product
# Create your views here.
def index(request):
return HttpResponse("Hello, world. You're at the product index.")
class ProductView(APIView):
def post(self, request):
serializer = ProductSerializers(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment