Skip to content
Advertisement

What does format=None do in Django rest full API

Recently when I read Django rest full API document I faced this code :

    def get(self, request, format=None):
    """Return a list of APIView features."""

    an_apiview = [
        'Uses HTTP methods as function (get, post, patch, put, delete).',
        'It is similar to a traditional Django view.',
        'Gives you most control over you logic.',
        'Its mapped manually to URLs.'
    ]

    return Response({'message': 'Hello!', 'an_apiview': an_apiview})

this code is work fine but I look for format=None and I cant find out what does it do. is any body know what is it and why its important to be?

Advertisement

Answer

The django rest framework (drf) documentation explains it here.

The gist of it is that when you want to support multiple file types in your response, drf provides a shortcut to support this, but requires you to include ‘format’ as a keyword argument.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement