'how to pass post parameter in Django rest swagger?

I have integrated swagger with django rest framework, but the swagger docs does not create a input box to post data for post request.

I am using Function based views with decorator(@api_view)

@api_view(['GET','POST'])
@permission_classes((AllowAny, ))
@renderer_classes([OpenAPIRenderer, SwaggerUIRenderer])
def preferences(request,format=None):
    try:
             "logic starts here "

in urls.py i have added:

  schema_view = get_swagger_view(title='API')         
  path('', schema_view, name="schema_view"),

in settings.py :

SWAGGER_SETTINGS = {
'USE_SESSION_AUTH': False,
'JSON_EDITOR': True,
'api_version': '0.1',
'enabled_methods': [
    'GET',
    'POST',
],
'SECURITY_DEFINITIONS': {
    "api_key": {
        "type": "apiKey",
        "name": "Authorization",
        "in": "header"
    },
},

}

But, when i open the api url i'm getting something like this (in image) where i'm unable to pass the parameters through postscreenshot of api hit url

what can be the problem here?is there any other changes to be done ?



Solution 1:[1]

When you click on the Try it Out link, you should get an input to fill in the POST data

Solution 2:[2]

make sure the class is imported from the generics API, example:

from rest_framework import generics

class Something (generics.GenericAPIView):

     serializer_class=SomeSerializer

     def post(self,request):
         pass

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ken4scholars
Solution 2 Jeremy Caney