My views:
def deleteDepartement(request):
object_id = request.POST.get('Id')
name= request.POST.get('name')
print(object_id)
print(name)
try:
D=Department.objects.get(id=object_id)
except:
print("NOT FOUND")
return redirect('department')
JavaScript code:
$.ajax({
type: 'POST',
url: "{% url 'deleteDepartement' %}",
data: {
csrfmiddlewaretoken: '{{ csrf_token }}',
Id:objectId,
name:'test',
},
});
I got none in value in django views. When I console.log
I got the id, but when i try to sent it i got none. Any suggestions please?
2
Answers
thanks for yoyr asnwer,i hope this image help ,i got id by adddeventlister and i try to pass it to django to delete the object
Can you please upload the image of request that browser is making from devtools (F12) with its headers and payload/data?
Also, how do you generate objectId in javascript code? is it already replaced in page source code when you inspect it or view using "view page source"?