0

Using Node JS, I want to get the data that I posted.

in my views. py

if request.method == 'POST':
        post_data = json.loads(request.POST.get("data"))
response = requests.post('http://localhost:3000/path/', data={
                                 'data': request.POST.get("data")})

in my node js

const bodyParser = require("body-parser")
const jsonParse = bodyParser.json()
router.post("/path", jsonParse, (req, res) => {
//I have some function here, but I needed to use the data from my 
django views.
console.log(req.body) //the console is {}, I want to get the data 
that I posted using the django views//})

Maybe my approach is wrong. I am new to node JS that's why I'm asking for help. I'm open to any suggestion. The django views are working. I just don't know how to receive that in Node JS way

1
  • may I know Post request of django working fine stand alone ? Commented Sep 29, 2022 at 9:46

1 Answer 1

1

For some reason the comment of Sir Harris brings me to check my django views. And I came up with solution. My node JS are now reading it

 data={'name':request.POST.get("device")}
        headers = {'content-type': 'application/json'}
        response = requests.post('http://localhost:3000/path', data=json.dumps(data), headers=headers)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.