From dae01c682122998f79cbca6ba78ae24eb4a1ba5b Mon Sep 17 00:00:00 2001 From: AdrienLSH Date: Thu, 18 Jan 2024 12:41:29 +0100 Subject: [PATCH] fix: 404 response on wrong api calls --- transcendence/urls.py | 4 +++- transcendence/views.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 transcendence/views.py diff --git a/transcendence/urls.py b/transcendence/urls.py index d0d06ad..fd3d6d9 100644 --- a/transcendence/urls.py +++ b/transcendence/urls.py @@ -15,7 +15,8 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path, include +from django.urls import path, include, re_path +from .views import handler_404_view urlpatterns = [ path('admin/', admin.site.urls), @@ -24,5 +25,6 @@ urlpatterns = [ path('api/chat/', include('chat.urls')), path('api/tournaments/', include('tournament.urls')), path('api/games/', include('games.urls')), + re_path(r'^api/', handler_404_view), path('', include('frontend.urls')), ] diff --git a/transcendence/views.py b/transcendence/views.py new file mode 100644 index 0000000..06fbe9b --- /dev/null +++ b/transcendence/views.py @@ -0,0 +1,7 @@ +from rest_framework.response import Response +from rest_framework.decorators import api_view +from rest_framework import status + +@api_view(('GET',)) +def handler_404_view(request): + return Response(status=status.HTTP_404_NOT_FOUND);