请求通过ajax渲染到一个不工作的页面django

时间:2013-07-26 10:36:58

标签: python ajax django

发出ajax请求后,数据成功发送到视图。但渲染功能不起作用。渲染函数应使用数据呈现给dashboard.html。我已导入渲染所需的所有文件。是因为ajax请求。提前谢谢......


我来自模板的ajax请求

$("#campaign").click(function () {
    alert("hey main")
    alert($("#campaign").val());
    var id = $("#campaign").val()
    $.ajax({
        type: "POST",
        url: "{% url 'appdata' %}",
        data: {
            userid: id
        }
    }).done(function () {
        alert("Data Sent: ");
    }).fail(function () {
        alert("error");
    });
    /* location.reload()*/
});

我的urls.py

url(r'^publisher/appdata/?$', 'appdata', name='appdata'),

我的views.py

def appdata(request):

    print 'hi i am appdata, fetch me after select id'

    print request
    userid = request.POST['userid']
    # print 'userid: %s'%userid
    impressions = Impressions.objects.get(id=userid)
    # print 'impressionid: %s'%impressions.id
    clicks = Clicks.objects.get(id=userid)
    revenues = Revenue.objects.get(id=userid)
    ecpm = App.objects.get(id=userid)
    member = Member.objects.get(id=userid)
    campaigns_id = Campaign.objects.get(id=userid)

    # print campaigns_id
    # print type(campaigns_id)
    apps = App.objects.all()
    # print apps

    # for i in apps:
        # print i.name
    # print len(camps)

    # dict = {'i':impressions, 'c':clicks, 'r':revenues, 'e':ecpm, 'apps': apps, 'member':member, 'c_id':campaigns_id } 
    # print dict['i'].impressions

    return render(request, 'dashboard.html', {'i':impressions, 'c':clicks, 'r':revenues, 'e':ecpm, 'apps': apps, 'member':member, 'c_id':campaigns_id })

0 个答案:

没有答案