I have a class-based view with a defined post method, which is the end-point of a file upload.
The request is made using the ng-file-upload module.
When executing the upload request, I receive a 405 Method not allowed error.
If I try to make a POST to that same URL with the same parameters (except for the file), it's working fine.
I can see in Firebug that the Response Headers are different:
- When sending the request via POST, the response's allowed method are POST and OPTIONS
- When sending via upload, they are GET, HEAD and OPTIONS
What could be causing this?
[edit] As requested, here is the (simplified) code of the view handling method:
def order_data(order, request):
"""
Return a serialized order with added permission information
"""
data = OrderSerializer(order).data
# Add a few custom fields on the data dict
return data
class SaveOrder(APIView):
def post(self, request):
data = request.data.get('order')
if data.get('id', None) is not None:
if not request.user.has_perm('orders.modify_order'):
return HttpResponseForbidden()
else:
order = Order.objects.get(id=data['id'])
else:
if not request.user.has_perm('orders.create_order'):
return HttpResponseForbidden()
else:
order = Order()
# Fill in order using the fields in data
order.save()
return JsonResponse(order_data(order, request))
[edit2] Actually the behaviour is not exactly what I've described earlier:
- With
uploadto url/order/save-orderI get an error saying that I need a trailing slash - With
uploadto url/order/save-order/I get a 405 - With
postto url/order/save-orderit's working fine (original code) - With
postto url/order/save-order/I get a 404