我知道这是一个非常基本的问题,但是在浪费了我一整天之后,我问了这个问题。我只是使用以下 AngularJS 代码向 Django 发送数据:
$http.post('/data/creation',
{
html: 'a'
}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
console.log(data);
console.log(status);
console.log(headers);
console.log(config);
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.log(status);
console.log(data);
});
在 Django 中:
@csrf_exempt
def snippets_post(request):
html = False
css = False
js = False
JSONdata = False
response = "You're looking at the results of question %s."
if request.method == 'POST':
try:
JSONdata = request.POST.get('data', False) # it was [] in actual
except:
JSONdata = 'ERROR'
return HttpResponse(JSONdata)
我得到 False 作为响应,“通过在 POST.get 中将数据替换为 html,结果是相同的”。我不知道这里出了什么问题。任何人都可以在这里帮助我吗?
谢谢