我有一个继承Allow
的DRF通用视图,但POST
标头不包含class OrdersView(CreateModelMixin, ListModelMixin, GenericAPIView):
filter_backends = (DjangoFilterBackend, OrderingFilter)
filter_fields = ('product', 'team', 'buy', 'open')
queryset = Order.objects.all()
serializer_class = OrderListSerializer
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)
:
POST
对网址的请求不会在Allow
标题中包含# OPTIONS /orders/
HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"name": "Orders",
"description": "",
"renders": [
"application/json",
"text/html"
],
"parses": [
"application/json",
"application/x-www-form-urlencoded",
"multipart/form-data"
]
}
:
POST
视图会处理Allow
个请求。我希望{{1}}标题准确无误。
答案 0 :(得分:0)
您需要确保拥有足够的权限才能使用POST操作。如果请求没有使用权限,DRF将不会在OPTIONS中显示它。