Python 无法获得AngularJS';Django中的s$http.post数据

Python 无法获得AngularJS';Django中的s$http.post数据,python,django,angularjs,angularjs-http,Python,Django,Angularjs,Angularjs Http,我知道这是一个非常基本的问题,但在浪费了一整天之后,我问了这个问题。我只是使用以下AngularJS代码向Django发送数据: $http.post('/data/creation', { html: 'a' }). success(function(data, status, headers, config) { // this ca

我知道这是一个非常基本的问题,但在浪费了一整天之后,我问了这个问题。我只是使用以下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)
通过将POST中的数据替换为html,我得到的响应为False,。get结果相同“。我不知道这里出了什么问题。有人能帮我吗


感谢

事实上,当我们使用$http的POST从AngularJs发送数据时,它会使用content type=“application/json”将数据发送到服务器。Django不理解这种格式。因此,您无法获取发送的数据

解决方案是使用以下配置更改内容类型标题:

    app.config(['$httpProvider', function ($httpProvider) {
        $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
}]);

请返回一个静态值并检查。。return HttpResponse(“post value”)…我怀疑URL是否会命中此代码段或某个地方?通信进展顺利,我得到的结果是错误的,因为post.get无法获取“数据”或“html”。问题是如何得到它?请通过点击F12,使用firebug或chrome网络选项卡跟踪请求,查看url是否包含请求处理时的html/数据。如果存在,则问题在于您的服务器端代码…当然,数据正在运行和检查,这是一些python/django问题,一些解析等。我在这里遗漏了这些,但是不能说。删除所有的行,然后像这个请求一样简单地尝试。发布['data']…检查这个线程是否有趣!很高兴知道这件事。谢谢通知:)谢谢,这也适用于Turbogears框架