Add books
This commit is contained in:
10
app/libros/urls.py
Normal file
10
app/libros/urls.py
Normal file
@ -0,0 +1,10 @@
|
||||
# app/libros/urls.py
|
||||
|
||||
from django.urls import path
|
||||
from app.libros.views import ping, LibrosList
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path("ping/", ping, name="ping"),
|
||||
path("api/libros/", LibrosList.as_view()),
|
||||
]
|
@ -1,11 +1,22 @@
|
||||
# app/libros/views.py
|
||||
|
||||
from django.http import JsonResponse
|
||||
from django.http import JsonResponse
|
||||
from rest_framework.views import APIView # nuevo
|
||||
from rest_framework.response import Response # nuevo
|
||||
from rest_framework import status # nuevo
|
||||
from .serializers import LibroSerializer # nuevo
|
||||
|
||||
|
||||
def ping(request):
|
||||
data = {"ping": "pong!"}
|
||||
return JsonResponse(data)
|
||||
|
||||
def ping(request):
|
||||
data = {"ping": "pong!"}
|
||||
return JsonResponse(data)
|
||||
|
||||
class LibrosList(APIView):
|
||||
|
||||
def post(self, request):
|
||||
serializer = LibroSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
Reference in New Issue
Block a user