我试图使用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')
请帮助!
答案 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