.. _form_data_stackover_1: ================================================================================= How to send the **formdata from the ajax to Django** view in PUT request? ================================================================================= .. seealso:: - https://stackoverflow.com/questions/59874632/how-to-send-the-formdata-from-the-ajax-to-django-view-in-put-request Problem ======== I am sending the ajax call to the python django view(no rest framework) and want to perform the update operation in django using PUT request. This update operation involved files too so I don't know to do PUT operation for files. I have performed GET, POST, DELETE operations but not understanding the PUT. I am sending the formdata object from the ajax. Thanks in advance!! Code ===== .. code-block:: html Bootstrap Example
.. code-block:: python @csrf_exempt def student_operation(request): if request.method == "GET": obj = Student.objects.all() return render(request, "datatables.html", {"obj": obj}) elif request.method == "POST": name = request.POST.get("name") age = request.POST.get("age") profile_photo = request.FILES.get("profile_photo") obj = Student(name=name, age=age, profile_photo=profile_photo) obj.save() return HttpResponse("success") elif request.method == "DELETE": data = json.loads(request.body) id = data.get('id') obj = Student.objects.get(id=id) obj.delete() return HttpResponse("success") elif request.method == "PUT": pass # Need to do code here