Created
September 29, 2024 09:03
-
-
Save pkbhowmick/a5b4c9d85b5ff529f65ef24a39ca576e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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