«message»: «Ошибка сети», «имя»: «Ошибка», «стек»: «Ошибка: ошибка сети \ n при> createError (http://localhost:3000/static/js/0.chunk.js:1970:15)\n в XMLHttpRequest.handleError
* 1017»*
api> urls.py
from django.urls import path
from .views import (
ItemListView,
AddToCartView,
OrderDetailView
)
urlpatterns = [
path('product-list/', ItemListView.as_view(), name='product-list'),
path('add-to-cart/', AddToCartView.as_view(), name='add-to-cart'),
path('order-summary/', OrderDetailView.as_view(), name='order-summary')
]
api> views.py
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import render, get_object_or_404
from django.utils import timezone
from rest_framework.generics import ListAPIView, RetrieveAPIView
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.status import HTTP_200_OK, HTTP_400_BAD_REQUEST
from core.models import Item, OrderItem, Order
from .serializers import ItemSerializer, OrderSerializer
class ItemListView(ListAPIView):
permission_classes = (AllowAny,)
serializer_class = ItemSerializer
queryset = Item.objects.all()
class OrderDetailView(RetrieveAPIView):
serializer_class = OrderSerializer
permission_classes = (IsAuthenticated,)
def get_object(self):
try:
order = Order.objects.get(
user=self.request.user, ordered=False)
except ObjectDoesNotExist:
return Response({"message": "You do not have an active order"}, status=HTTP_400_BAD_REQUEST)
constants.js
const localhost = "http://127.0.0.1:8000";
const apiURL = "/api";
export const endpoint = `${localhost}${apiURL}`;
export const productListURL = `${endpoint}/product-list/`;
export const addToCartURL = `${endpoint}/add-to-cart/`;
export const orderSummaryURL = `${endpoint}/order-summary/`;