'404 bad request react axios
I cant seem to figure out the error error 404 not found when I make a post request in react. Here is my react code for making post request. I am using Django restframork on the backend and react axios in the frontend and I am having post request error. Here are the details of code I used.
const handleUploadFile = (e) => {
let myfile = file;
let formData = new FormData();
formData.append('file', myfile);
formData.append('client', company_name);
formData.append('business_process', business);
http({
url: 'http://127.0.0.1:8000/api/business_process/upload-business-impact-excel-by-superuser',
method: 'POST',
mode: 'cors',
data: formData,
}).then(
(response) => {
alert('File uploaded Sesscessfully');
},
(err) => {
console.log(err);
}
);
};
Django views.py the view which used to make api request
class UploadBusinessImpactExcelBySuperUSer(APIView, ExcelHandlingView):
permission_classes = (
IsAuthenticated,
permissions.IsCybermindAdmin,
)
def post(self, request):
self.can_model_handle_ExcelHandlingView(models.BusinessImpact)
serializer = serializers.ExcelUploaderWithClient(data=request.data)
if serializer.is_valid():
data = serializer.validated_data
file = data.get("file")
client = data.get("client")
business_process_id = data.get("business_process")
try:
business_process = get_business_process_by_client(
client, business_process_id
)
except (
models.BusinessProcess.DoesNotExist,
accountModels.Client.DoesNotExist,
) as e:
return Response(
"business process or client does not exist",
status=status.HTTP_404_NOT_FOUND,
)
if (
file.content_type
== "application/vnd.openxmlformats-IsClientAdminofficedocument.spreadsheetml.sheet"
):
self.delete_every_record_that_match_criteria(
models.BusinessImpact,
{"client": client, "business_process": business_process},
)
excel_file = pd.read_excel(file)
data = pd.DataFrame(
excel_file,
columns=self.get_excel_fields(
models.BusinessImpact.excel_titles),
)
for _, row in data.iterrows():
self.create_model_object(
models.BusinessImpact,
row,
{"client": client, "business_process": business_process.id},
)
return Response("Successfully Loaded data from excel.")
else:
return Response(
{"file": ["File type must be excel with .xlxs extension."]},
status=status.HTTP_400_BAD_REQUEST,
)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
business_process/urls.py
urlpatterns = [
path(
"upload-business-impact-excel-by-superuser",
views.UploadBusinessImpactExcelBySuperUSer.as_view(),
),
]
urls.py main urls code
urlpatterns = [
path("admin/", admin.site.urls),
path("api/business_process/", include("business_process.urls")),
]
admin.site.site_header = settings.ADMIN_SITE_HEADER
Here is the request response network request response
How can I fix this problem?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
