skip to Main Content

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



  1. 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"?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search