I'm trying to do a POST request with some data to my Django script. It's just something for internal use so security isn't an issue, but it doesn't seem to want to print anything. It prints "TEST", so I know the post request is being received properly, but according to the Django docs, HttpRequest.POST should print a dictionary of the POST data.
Django
@csrf_exempt
def botdeposit(request):
if request.method == 'GET':
print(HttpRequest.GET)
return redirect('/')
elif request.method == 'POST':
print('TEST')
print(HttpRequest.POST)
return redirect('/')
node.js
var request = require('request');
// Set the headers
var headers = {
'User-Agent': 'Super Agent/0.0.1',
'Content-Type': 'application/x-www-form-urlencoded'
}
// Configure the request
var options = {
url: 'http://127.0.0.1:8000/test',
method: 'POST',
headers: headers,
form: {'key1': 'xxx', 'key2': 'yyy'}
}
// Start the request
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
// Print out the response body
console.log(body)
}
console.log(body);
})
1 Answer 1
request.POST will. HttpRequest is a class, and you have its instance. Just like docs say HttpRequest.method is a thing, but you write request.method.
(Yes, the docs are confusing, and not showing well the difference between class and instance values.)
2 Comments
print(HttpRequest.POST) with print(request.POST). (Same for GET, obviously,)