Django DRF Endpoint sin modelo
# Create a custom APIView
from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from . import serializers
from rest_framework import status
# Create your views here.
class HelloApiView(APIView):
serializer_class = serializers.HelloSerializer
def post(self, request):
"""Create a hello message with our name."""
serializer = serializers.HelloSerializer(data=request.data)
if serializer.is_valid():
name = serializer.data.get('name')
message = 'Hello {0}!'.format(name)
return Response({'message': message})
else:
return Response(
serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Jittery Jay