无法从Django调试器内部的Swagger UI访问传递的文件(PDB)

发布于 2025-02-11 15:54:16 字数 1701 浏览 3 评论 0原文

在包装的帮助下创建了API并在API中添加了Swagger

drf-yasg

当前更新版本1.20.0,然后添加了这样的代码,

success_res_data = openapi.Schema(type=openapi.TYPE_OBJECT, properties={'status': openapi.Schema(type=openapi.TYPE_NUMBER, title='200'), 'success': openapi.Schema(type=openapi.TYPE_OBJECT, properties={'message_header': openapi.Schema(type=openapi.TYPE_STRING), 'message': openapi.Schema(type=openapi.TYPE_STRING)})})
    
error_res_data = openapi.Schema(type=openapi.TYPE_OBJECT, properties={'status': openapi.Schema(type=openapi.TYPE_NUMBER, title='400'), 'error': openapi.Schema(type=openapi.TYPE_OBJECT, properties={'message_header': openapi.Schema(type=openapi.TYPE_STRING), 'message': openapi.Schema(type=openapi.TYPE_STRING)})})

class TestView(APIView):
    api_view = ['POST']
    authentication_classes = [SessionAuthentication, TokenAuthentication]

    invitation_file = openapi.Parameter('invitation_file', openapi.IN_QUERY, type=openapi.TYPE_FILE, required=True)

    @swagger_auto_schema(
        manual_parameters=[invitation_file], operation_description="description",
        responses={200: success_res_data, 400: error_res_data}
    )
    def post(self, request):
        invitation_file = request.data.get('invitation_file', None)

    invitation_file = openapi.Parameter('invitation_file', openapi.IN_QUERY, type=openapi.TYPE_FILE, required=True)

    @swagger_auto_schema(
        manual_parameters=[invitation_file], operation_description="description",
        responses={200: success_res_data, 400: error_res_data}
    )
    def post(self, request):
        invitation_file = request.data.get('invitation_file', None)

即使我们从前端传递文件,

created an api and added swagger to the api with the help of the package

drf-yasg

the current updated version 1.20.0, then added code like this

success_res_data = openapi.Schema(type=openapi.TYPE_OBJECT, properties={'status': openapi.Schema(type=openapi.TYPE_NUMBER, title='200'), 'success': openapi.Schema(type=openapi.TYPE_OBJECT, properties={'message_header': openapi.Schema(type=openapi.TYPE_STRING), 'message': openapi.Schema(type=openapi.TYPE_STRING)})})
    
error_res_data = openapi.Schema(type=openapi.TYPE_OBJECT, properties={'status': openapi.Schema(type=openapi.TYPE_NUMBER, title='400'), 'error': openapi.Schema(type=openapi.TYPE_OBJECT, properties={'message_header': openapi.Schema(type=openapi.TYPE_STRING), 'message': openapi.Schema(type=openapi.TYPE_STRING)})})

class TestView(APIView):
    api_view = ['POST']
    authentication_classes = [SessionAuthentication, TokenAuthentication]

    invitation_file = openapi.Parameter('invitation_file', openapi.IN_QUERY, type=openapi.TYPE_FILE, required=True)

    @swagger_auto_schema(
        manual_parameters=[invitation_file], operation_description="description",
        responses={200: success_res_data, 400: error_res_data}
    )
    def post(self, request):
        invitation_file = request.data.get('invitation_file', None)

    invitation_file = openapi.Parameter('invitation_file', openapi.IN_QUERY, type=openapi.TYPE_FILE, required=True)

    @swagger_auto_schema(
        manual_parameters=[invitation_file], operation_description="description",
        responses={200: success_res_data, 400: error_res_data}
    )
    def post(self, request):
        invitation_file = request.data.get('invitation_file', None)

this invitation_file variable is returning None even if we pass the file from front-end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你又不是我 2025-02-18 15:54:16

经过一些研究并在Postman中检查了相同的API之后,将代码从上面的内容更改为

success_res_data = openapi.Schema(type=openapi.TYPE_OBJECT, properties={'status': openapi.Schema(type=openapi.TYPE_NUMBER, title='200'), 'success': openapi.Schema(type=openapi.TYPE_OBJECT, properties={'message_header': openapi.Schema(type=openapi.TYPE_STRING), 'message': openapi.Schema(type=openapi.TYPE_STRING)})})
    
error_res_data = openapi.Schema(type=openapi.TYPE_OBJECT, properties={'status': openapi.Schema(type=openapi.TYPE_NUMBER, title='400'), 'error': openapi.Schema(type=openapi.TYPE_OBJECT, properties={'message_header': openapi.Schema(type=openapi.TYPE_STRING), 'message': openapi.Schema(type=openapi.TYPE_STRING)})})

class TestView(APIView):
    api_view = ['POST']
    authentication_classes = [SessionAuthentication, TokenAuthentication]

    invitation_file = openapi.Parameter('invitation_file', openapi.IN_QUERY, type=openapi.TYPE_FILE, required=True)


    @swagger_auto_schema(
            manual_parameters=[invitation_file],operation_description="API Description", consumes="multipart/form-data",
        responses={200: success_res_data, 400: error_res_data}
    )
    def post(self, request):
        invitation_file = request.data.get('invitation_file', None)

    invitation_file = openapi.Parameter('invitation_file', openapi.IN_QUERY, type=openapi.TYPE_FILE, required=True)

    @swagger_auto_schema(
        manual_parameters=[invitation_file], operation_description="description",
        responses={200: success_res_data, 400: error_res_data}
    )
    def post(self, request):
        invitation_file = request.data.get('invitation_file', None)

现在,请单击API右侧的解锁按钮,并添加“ token auth-token-token < /strong>”,

然后在调用API并使用PDB后立即单击“身份验证”

after a little research and checking the same api in postman, changed the code from whats above to

success_res_data = openapi.Schema(type=openapi.TYPE_OBJECT, properties={'status': openapi.Schema(type=openapi.TYPE_NUMBER, title='200'), 'success': openapi.Schema(type=openapi.TYPE_OBJECT, properties={'message_header': openapi.Schema(type=openapi.TYPE_STRING), 'message': openapi.Schema(type=openapi.TYPE_STRING)})})
    
error_res_data = openapi.Schema(type=openapi.TYPE_OBJECT, properties={'status': openapi.Schema(type=openapi.TYPE_NUMBER, title='400'), 'error': openapi.Schema(type=openapi.TYPE_OBJECT, properties={'message_header': openapi.Schema(type=openapi.TYPE_STRING), 'message': openapi.Schema(type=openapi.TYPE_STRING)})})

class TestView(APIView):
    api_view = ['POST']
    authentication_classes = [SessionAuthentication, TokenAuthentication]

    invitation_file = openapi.Parameter('invitation_file', openapi.IN_QUERY, type=openapi.TYPE_FILE, required=True)


    @swagger_auto_schema(
            manual_parameters=[invitation_file],operation_description="API Description", consumes="multipart/form-data",
        responses={200: success_res_data, 400: error_res_data}
    )
    def post(self, request):
        invitation_file = request.data.get('invitation_file', None)

    invitation_file = openapi.Parameter('invitation_file', openapi.IN_QUERY, type=openapi.TYPE_FILE, required=True)

    @swagger_auto_schema(
        manual_parameters=[invitation_file], operation_description="description",
        responses={200: success_res_data, 400: error_res_data}
    )
    def post(self, request):
        invitation_file = request.data.get('invitation_file', None)

now click on the unlock button on the right of the api and add the "Token auth-token" and click authenticate

now after calling the api and using pdb the value of the passed file is shown for the variable invitation_file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文