format=none 在 django Rest Framework apiview 中引用什么?

6 django django-rest-framework

文档在这里:http ://www.django-rest-framework.org/api-guide/views/#get_permissionsself

在此示例中,格式设置为 none 但没有引用它:

class ListUsers(APIView):
    """
    View to list all users in the system.

    * Requires token authentication.
    * Only admin users are able to access this view.
    """
    authentication_classes = (authentication.TokenAuthentication,)
    permission_classes = (permissions.IsAdminUser,)

    def get(self, request, format=None):
        """
        Return a list of all users.
        """
        usernames = [user.username for user in User.objects.all()]
        return Response(usernames)
Run Code Online (Sandbox Code Playgroud)

我检查了源代码,仍然没有参考格式。

欣赏一些清晰度

小智 5

您可以在 URL 中使用它们来附加后缀内容类型格式(HTML、JSON 或 API)。你可以在这里读到它:

http://www.django-rest-framework.org/tutorial/2-requests-and-responses/#adding-optional-format-suffixes-to-our-urls