Search code examples
pythondjangodjango-rest-frameworkmetadatadjango-countries

How to return actions and parameters in OPTIONS request with django rest framework


I try to return a list of select options for countries using django-countries and django rest framework. I use JWT_AUTH for the authentication.

When I try a options request:

curl \
  -H "Authentication: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFsYmVydG9fdmVudGEiLCJ1c2VyX2lkIjoyLCJlbWFpbCI6IiIsImV4cCI6MTUwODE2Mzg4Mn0.svxqTThCahSl1Vu27sMjuJyd1PRLk28-Xgn2OKKb5-g"\
  -X OPTIONS \
  -v http://127.0.0.1:8000/api/v1/core/perfilViajeroUserPass/

The response is:

{
 "name":"Perfil Viajero User Pass Create",
 "description":"",
 "renders":["application/json","text/html"],
 "parses":[
           "application/json",
           "application/x-www-form-urlencoded",
           "multipart/form-data"
          ]
}

But I think that it should be something like this by default:

{
"name": "To Do List",
"description": "List existing 'To Do' items, or create a new item.",
"renders": [
    "application/json",
    "text/html"
],
"parses": [
    "application/json",
    "application/x-www-form-urlencoded",
    "multipart/form-data"
],
"actions": {
    "POST": {
        "note": {
            "type": "string",
            "required": false,
            "read_only": false,
            "label": "title",
            "max_length": 100
        }
    }
}

}

Someone could help me? thanks.


Solution

  • I have found the solution.

    I change my view class type from APIView to generics.CreateAPIView and know it works. Thank you very much.