从ManualSchema字段coreapi django

时间:2019-05-22 02:58:28

标签: django core-api

我写了一个manualSchema:

send_ticket_comment_schema = ManualSchema(fields=[
    coreapi.Field(
        "id",
        required=True,
        location="path",
        schema=coreschema.Integer(),
        description='The ticket id'
    ),
    coreapi.Field(
        "text",
        required=True,
        location="body",
        schema=coreschema.String(),
        description='The comment of the ticket'
    )
], description='Add a comment to the ticket')

然后将其添加到Django的@action中:

@action(detail=True, methods=['post'], schema=send_ticket_comment_schema)
    def create_comment(self, request, pk=None):
        """
        Endpoint to create a comment
        """
        user = request.user

        ticket = self.get_object()
        body = json.loads(request.body)

但是当我尝试访问请求正文的值时,我得到了django.http.request.RawPostDataException: You cannot access body after reading from request's data stream

如何修改操作的手动模式以获取对其的访问权限?

0 个答案:

没有答案