1

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);
})
asked Apr 21, 2015 at 1:52
0

1 Answer 1

2

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.)

answered Apr 21, 2015 at 1:55
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, i'm not sure I understand your answer. I want to get the form values passed through, how could I do that? Thanks for responding.
Literally, replace print(HttpRequest.POST) with print(request.POST). (Same for GET, obviously,)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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