0leg
0leg

Reputation: 14144

Django REST shows non-allowed methods under Allow in the Browser

Goal

Is to disable OPTIONS method globally.

Background

According to the official Django REST docs (https://www.django-rest-framework.org/api-guide/metadata/), the proper way to do it is to set DEFAULT_METADATA_CLASS to None.

This resolves the problem. After trying to send the OPTIONS curl request, the server responds with the 405.

Problem

However the API Browser would still show methods under Allow that are actually not allowed:

enter image description here

Question

How to hide not-supported methods under Allow in Django API Browser?

Upvotes: 2

Views: 653

Answers (1)

0leg
0leg

Reputation: 14144

After checking the Disable a method in a ViewSet, django-rest-framework, it turned out there are at least 3 good approaches to address this:

  1. Use Specific ViewSets instead of just inheriting ModelViewSet
  2. Overwrite _allowed_methods()
  3. Define http_method_names()

It was decided to:

  1. Set DEFAULT_METADATA_CLASS to None (to make sure non-defined methods are not exposed).
  2. Define http_method_names for each ViewSet (to hide them in the Browser API).

Upvotes: 1

Related Questions