Django如何使用请求为$http的render-tu响应

2024-09-23 10:32:47 发布

您现在位置:Python中文网/ 问答频道 /正文

在Django中,当请求来自angularjs的$http时,可以使用render_to_响应? 示例:

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

此按钮将参数传递给文件数据中post_dados()中的函数_应用程序js在

^{pr2}$

在网址.py在

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

在视图.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) {...},而{}不将信息发送到速率.html,只是去速率.html如果源是窗体。在

是否可以使用响应u来呈现?如果可能,我怎么做?在


Tags: topydivsendjsonreturnhtmltype