4Manuals

  • PDF Cloud HOME

Django Rest框架解析器在所有语句执行之前返回 Download

    如何将文本边界框与pyplot.Rectangle对齐? 导入类问题 在Python数据框中选择列时出错 使用Rabbit的pika确认消息 如何在按住键的同时暂停VideoStream? Python OpenCV TypeError:无法处理此数据类型 使用buildozer不会下载sdl2_image Django Rest Framework-根据字段内容进行序列化 SMTPSenderRefused,421,超出超时 Tensorflow多线程推理比单线程推理慢

我正在使用django的{​​{1}}频道上可用的最新版本的django-rest-framework和stable-但是,该问题在较旧的代码库上是可重现的({{1 }} pipy版。

问题是当我尝试定义自定义解析器时(根据here),下面显示了说明该问题的示例:

django

还有一个可以使用的非常简单的测试视图:

2.x

我假设这两个import logging import json import jsonschema from rest_framework.exceptions import ParseError from rest_framework.parsers import JSONParser log = logging.getLogger('logger') class JSONCustomParser(JSONParser): def parse(self, stream, media_type=None, parser_context=None): data = super(JSONCustomParser, self). \ parse(stream, media_type, parser_context) try: # these are executed normally a = 1 b = 2 # problematic bits: un-comment either of these and execution ends early. # data = json.load(stream.read()) # data = json.load("{}") # data = JSONParser().parse(stream) # auth_name = str(parser_context['request'].auth.application) # sample commands not executed if they are *after* the above and either if them is # un-commented a = a + a b = a + 2 except ValueError: log.error("Value error") else: return data 消耗操作会强制返回,尽管并不确定,因为无论如何class TestView(APIView): """ Simple test view to test the parser """ parser_classes = (JSONCustomParser,) permission_classes = () def post(self, request): content_length = request.META['CONTENT_LENGTH'] return Response({'received': content_length}) 在调用stream中消耗了流…但是,我不是确定其他人为什么提出问题...

0 个答案:

没有答案



Similar searches
    如何在 如何触发onSubmit的最终表单? 使用Shell脚本删除折线 如何通过动态生成的RaisedButton onpress事件在父类上调用funcion 我试图通过从文件中读取来制作链接列表