在Django Rest Full API中format = None什么都不做

时间:2018-11-29 21:48:54

标签: python django python-3.x django-rest-framework django-views

最近,当我阅读Django rest full API文档时,我遇到了以下代码:

    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})

此代码可以正常工作,但是我正在寻找format=None,但找不到它的作用。有人知道它是什么,为什么重要吗?

1 个答案:

答案 0 :(得分:4)

django rest框架(drf)文档here对其进行了说明。

要点是,当您想要在响应中支持多种文件类型时,drf提供了一种支持此功能的快捷方式,但是要求您将“格式”作为关键字参数。