什么格式= djano休息框架apiview中没有引用?

时间:2017-10-20 19:19:53

标签: 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)

我检查了源代码,但仍未提及格式。

欣赏一些清晰度

1 个答案:

答案 0 :(得分:0)

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

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