Django:如何从jquery获取传递给视图的url参数

时间:2017-09-21 13:26:22

标签: javascript jquery python django

这是我的网址格式:

  url(r'^(?P<pk>\d+)/view/$', views.leave_view, name='leave_view')

my views.py

def leave_view(request,pk):
    leaves=leave.objects.get(id=pk);
    data=dict()
    if request.method == 'POST':
        data['html_form']= render_to_string('m_manage/view_modal.html', {'leaves':leaves}, request=request)
    return JsonResponse(data) 

我的电话 js ----点击按钮调用

<script>
    $("#table").on('click', '.view', function (e) {
        var btn = $(this);
        console.log(btn);
        var url = btn.attr("data-url");
        console.log(url);
        $.ajax({
            // url: '/m_manage/leave_view/', 
            url: btn.attr("data-url"),
            dataType: 'json',
            type: 'get',
            success: function (data) {
                console.log('You Did it!!!!');
                console.log(data);
                $("#modal-leave .modal-content").html(data.html_form);
            }
        });
    });
</script>

我的console.log(数据)打印没有,虽然我从url收集主键并编写查询...为什么没有数据...

0 个答案:

没有答案