I am building an API which accepts file and validates it, sends json response (not storing the file in db, so no need of model). I have created a class based view, in post function, request.FILES or request.POST doesn’t contain the file… If I make a form, it will work. But, I don’t want any UI, it should be a simple API. Anyone knows how to do it?
class ValidateView(View):
def get(self, request, *args, **kwargs):
pass
def post(self, request, *args, **kwargs):
file = request.FILES
if not file:
return JsonResponse({"status_code": "400", "message": "a file is required", "status_response": "Bad Request"})
return JsonResponse({"status_code": "200", "message": "data validated", "status_response": "Success"})
@csrf_exempt
def dispatch(self, request, *args, **kwargs):
return super(ValidateView, self).dispatch(request, *args, **kwargs)
No responses yet.