Django - 如何使用其请求为$ http的render_to_response

时间:2015-02-24 20:11:08

标签: python django angularjs http render

在Django中,当请求来自$ http of angularjs时,可以使用render_to_response吗? 例如:

<!--proposta.html-->
<div ng-app='App' ng-controller="MyCtrl">
    <input type="submit" value="Gerar" ng-click="post_dados(x)">
</div>

此按钮将参数传递给文件data_app.js中post_dados()中的函数

var myApp = angular.module('App', []);
function MyCtrl($scope,$http,$sce) {
   $scope.retorno
   $scope.post_dados = function (lista) {
       $http({
           method:'POST',
           url:'/send_proposta/',
           data: lista,
           headers:{'Content-Type': 'application/x-www-form-urlencoded'},
       }).success(function(retorno){
           $scope.retorno=retorno
         })
   }
}

urls.py

urlpatterns = patterns('',
   url(r'^send_proposta/$', 'mge.core.views.send_proposta'),)

views.py

def send_proposta(request):
    proposta_tratada, header = tratar_proposta(request.POST)
    if proposta_tratada=='erro':
        json_erro=simplejson.dumps('Incorrect reporting of the Proposal, fill again')
        return HttpResponse(json_erro, content_type ="application/json")
    else:
        table_edit=valido(proposta_tratada, header)
        return render_to_response('rateio.html', {'x' :  table_edit})

返回HttpResponse会将邮件发送到.success (function (return) {...}return render_to_response ('rateio.html', {x:. table_edit})不会将信息发送到rateio.html,如果源是表单,则转到rateio.html。

可以在$ http中使用render_to_response吗?如果可能的话,我怎么能这样做?

0 个答案:

没有答案