【问题标题】:what does format=none reference in django rest framework apiview?django rest framework apiview 中的 format=none 引用了什么?
【发布时间】:2017-10-20 19:19:52
【问题描述】:

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

在此示例中,格式设置为无但不引用它:

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)

我检查了源代码,仍然没有提到格式。

欣赏一些清晰

【问题讨论】:

    标签: django django-rest-framework


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-06
      • 1970-01-01
      • 1970-01-01
      • 2020-10-07
      • 1970-01-01
      • 2019-10-04
      • 2018-12-06
      • 2017-04-04
      相关资源
      最近更新 更多