1
因此,我有我的刪除函數的問題,它刪除對象的意思,但不會去window.location。相反,我得到錯誤Django刪除()成功函數錯誤
DoesNotExist at/api/personnel/delete/ 資源匹配查詢不存在。
我想象的是因爲它剛剛被刪除。我如何克服這個問題?
var deletepers = function(){
var persid = getUrlVars()["id"];
data={persid}
console.log(persid);
$.ajax({
type: "POST",
url: "/api/personnel/delete/",
data: JSON.stringify(data),
contentType: "application/json",
dataType: 'json',
success:function(response){
window.location.href = "/Personnel";
}
})
}
def delete_personnel(request):
# Try find the requested app
if request.method == "POST":
pers_id = request.POST.get('persid')
pers = Resource.objects.get(id=pers_id)
if not pers: return HttpResponseNotFound()
pers.delete()
return HttpResponse(content_type='application/json')
沒有關係,但如果你想你的頁面得到刷新,你爲什麼用javascript刪除?你爲什麼不用普通的視圖去做刪除? –
那會怎麼樣? – SpeedyH30
http://stackoverflow.com/questions/311188/how-do-i-edit-and-delete-data-in-django?answertab=votes#tab-top –