[Error][1]
AssertionError at /api/client-details/ Expected view Client_view to be called with a URL keyword argument named "pk". Fix your URL conf, or set the `.lookup_field` attribute on the view correctly. Request Method: DELETE Request URL:
http://127.0.0.1:8000/api/client-details/ Django Version: 2.2.6 Python Executable: C:\Users\AravindManoj\PycharmProjects\Client\venv\Scripts\python.exe Python Version: 3.7.4 Python Path:
['C:\\Users\\AravindManoj\\PycharmProjects\\Client\\Client',
'C:\\Users\\AravindManoj\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip',
При использовании общего представления в Django отображается ошибка при использовании функции DELETE. Пожалуйста, кто-нибудь даст мне синтаксис общих видов в наборе моделей, я не нашел никаких проблем, но не удалил функцию
Views.py
from django.http import Http404, HttpResponse
from rest_framework import viewsets, status, generics
from rest_framework.decorators import api_view
from rest_framework.response import Response
from .serializers import ClassSerializer
from .models import Client
class Client_view(viewsets.ModelViewSet, generics.RetrieveUpdateDestroyAPIView):
queryset = Client.objects.all().order_by('-Name')
serializer_class = ClassSerializer*
lookup_fields = ['Name', 'UserName', 'Mobile', 'Email', 'Address']
urls.py
from rest_framework import routers
from .views import Client_view
router = routers.DefaultRouter()
router.register('', Client_view)
urlpatterns = router.urls
models.py
from django.db import models
class Client(models.Model):
Name = models.CharField(max_length=15)
UserName = models.CharField(max_length=15)
Email = models.CharField(max_length=20)
Mobile = models.CharField(max_length=10)
Address = models.CharField(max_length=20)
serializer.py
from rest_framework import serializers
from .models import Client
class ClassSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Client
fields = ['Name', 'UserName', 'Email', 'Mobile', 'Address']