找不到Django Ajax GET网址

时间:2018-08-16 12:07:24

标签: javascript python jquery ajax django

我试图使用Ajax和Django 1.11传递参数,并得到未找到错误:/ enquiry / followup_alter /。这是代码。

错误:

    Not Found: /enquiry/followup_alter/

Ajax:

    $(document).ready(function () {
      $(".remove").click(function () {
        $(this).parents('tr').hide();
        var a_href = $(this).attr('href');
        $.ajax({
            type:"GET",
            url:"/enquiry/followup_alter/",
            data:"id=" +a_href,
            success: function (response) {
                alert(response)
            }
        });
      });
    })

enquiry / urls.py:

    url(r'^followup_alter/id=(?P<id>[\d]+)/$', views.followup_alter),

views.py:

    def followup_alter(request,id):
      get = Followup.objects.get(id = id)
      get.status = 1
      get.save()
      return HttpResponse('Entry Removed')

请帮助!

1 个答案:

答案 0 :(得分:0)

id是作为GET参数发送的,而不是作为URL的一部分发送的。

type:"GET",
url:"/enquiry/followup_alter/",
data:"id=" +a_href,

那应该得到/enquiry/followup_alter/?id=123

r'^followup_alter/id=(?P<id>[\d]+)/$

这需要一个URL /enquiry/followup_alter/id=123