【问题标题】:Django json data in request.body but emptyrequest.body 中的 Django json 数据但为空
【发布时间】:2016-07-23 05:01:38
【问题描述】:

我正在使用需要向 url 发送回调的 API。因此我配置了我的 url 和我的视图:

def get_callback(request):
    ...
    some treatment with request.body

我的视图总是返回 request.body 包含“b''”。但是,它必须包含大量以 JSON 编码的信息。 事实上,我知道这些信息已经很好地发送到回调 url,我尝试使用 requestbin.in (http://requestb.in/1d4dkk01?inspect#10fl7s) 并且原始正文已满。

什么情况下身体是空的?可能是nginx配置?还是在 setting.py 中?

谢谢你

【问题讨论】:

  • Requestbin 显示Content-Type: multipart/form-data,没有json。

标签: python json django nginx request


【解决方案1】:

我认为,您应该返回响应具有某种 json 数据以供查看。喜欢它

   import json
   def get_call_back(request):
          # Do something to return dictionary same as {'abc': xyz}
          json_data = json.dumps(data) 
          return HttpResponse(json_data, content_type='application/json')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-27
    • 2019-02-01
    • 2023-03-08
    • 1970-01-01
    • 2017-08-27
    • 2019-04-13
    • 1970-01-01
    • 2022-06-29
    相关资源
    最近更新 更多