无法从Django调试器内部的Swagger UI访问传递的文件(PDB)
在包装的帮助下创建了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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一些研究并在Postman中检查了相同的API之后,将代码从上面的内容更改为
现在,请单击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
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