请求从django发送到nodejs

时间:2017-05-02 14:57:18

标签: python node.js django post python-requests

我尝试将数据从django发送到nodejs。我收到但无法读取数据参数。

Django的:

response = {
        "status": "success",
        "voto":  all_votes,
        "user_choice": new_vote.value if new_vote else None
}    
import requests
requests.post('http://localhost:8081/vote_added', data = response)

的NodeJS:

//router/index
router.post('/vote_added', votes.vote_added);

//votes controller
module.exports.vote_added = function(req, res) {
  console.log("test", req.params)
  console.log("test2", req.body)
  console.log("test3", req.query)
}

ps:我的response是一个词典

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。只需将数据更改为django请求中的参数:

requests.post('http://localhost:8081/vote_added', data = response)

requests.post('http://localhost:8081/vote_added', params = response)

并在nodejs中使用req.query