【问题标题】:django - request.META - when sending request, what to do so that data appears in request.METAdjango - request.META - 发送请求时,如何使数据出现在 request.META 中
【发布时间】:2013-07-28 04:51:23
【问题描述】:

在 Django 中,request.META 中有很多东西,而我当前的代码会检查 request.META 中的 HTTP_TOKEN 之类的内容,因此在发送请求时,我需要向该 url 发送请求,以便在接收服务器中出现数据在 request.META 中。

我认为标题出现在那里,所以我尝试了这个:

  python example:(I am sending request from javascript, but getting it work from any client is enough so I can implement finally using javascript).
  r = requests.get(url, headers={'HTTP_TOKEN': 'abc'})

但在收到请求后,我在 request.META 中没有找到类似 HTTP_TOKEN 的内容。

【问题讨论】:

    标签: python django


    【解决方案1】:

    With the exception of CONTENT_LENGTH and CONTENT_TYPE, as given above, any HTTP headers in the request are converted to META keys by converting all characters to uppercase, replacing any hyphens with underscores and adding an HTTP_ prefix to the name. So, for example, a header called X-Bender would be mapped to the META key HTTP_X_BENDER.

    https://docs.djangoproject.com/en/dev/ref/request-response/

    所以,就你而言,我认为你只需发送{"TOKEN": "abc"}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-27
      • 2020-09-28
      • 2022-12-22
      • 2017-08-10
      • 2018-01-09
      • 2021-09-20
      • 2019-09-26
      相关资源
      最近更新 更多