Страница не найдена (404), Пустой путь не совпал ни с одним из этих путей
Я знаю, что этот вопрос задается в разных формах, но я не могу найти решение для своей проблемы;
Моя проблема в том, что мне нужно отображать статические страницы, и я столкнулся с этой ошибкой: введите описание изображения здесь
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in djangoAPIReact.urls, Django tried these URL patterns, in this order:
admin/
^ ^department$ [name='department']
^ ^department/([0-9]+)$ [name='departmentApi']
^ ^employee$ [name='employee']
^ ^employee/([0-9]+)$ [name='employeeApi']
^ ^Employee/SaveFile$ [name='SaveFile']
^ ^media/(?P<path>.*)$
The empty path didn’t match any of these.
Я также использовал URL вместо re_path, но это не работает, я новичок в Django, пожалуйста, любая помощь будет оценена по достоинству.
Вот мой код:
`urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'^', include('EmployeeApp.urls'))
]`
App.urls:
`urlpatterns=[
re_path(r'^department$',views.departmentApi, name='department'),
re_path(r'^department/([0-9]+)$',views.departmentApi, name='departmentApi'),
re_path(r'^employee$',views.employeeApi, name='employee'),
re_path(r'^employee/([0-9]+)$',views.employeeApi, name='employeeApi'),
re_path(r'^Employee/SaveFile$', views.SaveFile, name='SaveFile')
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)`
Вид:
@csrf_exempt
def departmentApi(request, id=0):
if request.method == 'GET':
department = Departments.objects.all()
departments_serializer = DepartmentSerializer(department, many=True)
return JsonResponse(departments_serializer.data, safe=False)
elif request.method == 'POST':
department_data = JSONParser().parse(request)
department_serializer = DepartmentSerializer(data=department_data)
if department_serializer.is_valid():
department_serializer.save()
return JsonResponse("Added Successfully!!", safe=False)
return JsonResponse("Failed ro Add.",safe=False)
elif request.method=='PUT':
department_data = JSONParser().parse(request)
department=Departments.objects.get(DepartmentId=department_data['DepartmentId'])
department_serializer=DepartmentSerializer(department,data=department_data)
if department_serializer.is_valid():
department_serializer.save()
return JsonResponse("Updated Successfully!!", safe=False)
return JsonResponse("Failed to Update.", safe=False)
elif request.method == 'DELETE':
department = Departments.objects.get(DepartmentId=id)
department.delete()
return JsonResponse("Deleted Successfully!!", safe=False)
@csrf_exempt
def employeeApi(request,id=0):
if request.method=='GET':
employees = Employees.objects.all()
employees_serializer = EmployeeSerializer(employees, many=True)
return JsonResponse(employees_serializer.data, safe=False)
elif request.method=='POST':
employee_data=JSONParser().parse(request)
employee_serializer = EmployeeSerializer(data=employee_data)
if employee_serializer.is_valid():
employee_serializer.save()
return JsonResponse("Added Successfully!!" , safe=False)
return JsonResponse("Failed to Add.",safe=False)
elif request.method=='PUT':
employee_data = JSONParser().parse(request)
employee=Employees.objects.get(EmployeeId=employee_data['EmployeeId'])
employee_serializer=EmployeeSerializer(employee,data=employee_data)
if employee_serializer.is_valid():
employee_serializer.save()
return JsonResponse("Updated Successfully!!", safe=False)
return JsonResponse("Failed to Update.", safe=False)
elif request.method=='DELETE':
employee=Employees.objects.get(EmployeeId=id)
employee.delete()
return JsonResponse("Deleted Succeffully!!", safe=False)
@csrf_exempt
def SaveFile(request):
file=request.FILES['myFile']
file_name = default_storage.save(file.name,file)
return JsonResponse(file_name,safe=False)