weixin_33733810 2018-08-16 12:07 采纳率: 0%
浏览 52

找不到Django Ajax GET网址

I am trying to pass parameters using Ajax and Django 1.11 and getting the error Not Found: /enquiry/followup_alter/.Here is the code.

Error:

    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')

Please help!

  • 写回答

1条回答 默认 最新

  • weixin_33725722 2018-08-16 15:56
    关注

    The id is sent as a GET parameter, not as part of the URL.

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

    That should result in /enquiry/followup_alter/?id=123.

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

    This expects a URL /enquiry/followup_alter/id=123

    评论

报告相同问题?