我在我的 ModelViewSet 上添加了一个装饰方法。它没有按我的预期工作。我可以浏览到“/customers/1/add”,但“/customers/1/add/1”返回 404。为什么?
from rest_framework import routers, viewsets
from rest_framework.decorators import action
from app1.models import Customer
class CustomerViewSet(viewsets.ModelViewSet):
model = Customer
@action()
def add(self, request, pk=None):
queryset = Customer.objects.all()
router = routers.DefaultRouter()
router.register(r'customers', CustomerViewSet)