В моем проекте Django и DRF я получаю ошибку сервера для моей правильной рабочей ссылки, и страницу 404 not found для отсутствующего url после добавления страницы 404

Привет, у меня есть проект Blog post, некоторые функциональные возможности сделаны с DRF и некоторые функциональные возможности сделаны с Django.Мне нужно добавить 404 страницу для отсутствующих урлов. Но если я использую правильную рабочую ссылку, я получу ошибку сервера, однако, я получу 404 страницу для отсутствующих url. Например, такие url, как '127.0.0.1:8000/en/me' или '127.0.0.1:8000/en/me/contact/' или '127.0.0.1:8000/en/book' приведут к ошибке сервера, но url '127.0.0.1:8000/en/men' возвращает не найденную страницу

в моем django_project/urls.py:

from django.contrib import admin
from django.urls import path, include

from django.conf.urls.static import static
from django.conf import settings

from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

from django.conf.urls.i18n import i18n_patterns


# from django.conf.urls import handler404
from my_works import views as my_works_views

schema_view = get_schema_view(
   openapi.Info(
      title="API Docs",
      default_version='v1',
      description="API urls description",
      terms_of_service="https://www.myblogs.com/policies/terms/",
      contact=openapi.Contact(email="aahmadov271101@gmail.com"),
      license=openapi.License(name="Test License"),
   ),
   public=True,
   permission_classes=(permissions.AllowAny,),
)

urlpatterns = [

    path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
    path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
    path('i18n/', include('django.conf.urls.i18n')),   
]

urlpatterns += i18n_patterns (

    path('', include('my_works.urls')),
    path('me/', include('accounts.urls')),   
    path('admin/', admin.site.urls),
)
urlpatterns+= (static(settings.STATIC_URL, document_root=settings.STATIC_ROOT))
urlpatterns+= (static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT))
handler404 = 'accounts.views.error_404_view'

admin.site.site_header = 'Alimardon Mustafoqulov Administration'
admin.site.site_title = 'Administration'
admin.site.index_title = 'Administration page'

в моем django_app/urls.py:

from django.urls import path, include
from django.conf.urls.i18n import i18n_patterns
from .views import (
    ArticlesViewList,
    BooksViewList,
    PresentationsViewList,
    ProjectsViewList,
    EventsViewList,
    VideosViewList,
    )
from rest_framework import routers
from django.conf.urls import handler404

router = routers.DefaultRouter()

router.register(r'articles', ArticlesViewList, basename='articles')
router.register(r'books', BooksViewList, basename='books')
router.register(r'presentations', PresentationsViewList, basename='presentations')
router.register(r'projects', ProjectsViewList, basename='projects')
router.register(r'events', EventsViewList, basename='events')
router.register(r'videos', VideosViewList, basename='videos')

urlpatterns = []

urlpatterns += router.urls

в моем django_app2/urls.py:

from django.urls import path, include
from .views import ContactAPIView, ProfileView, AdminContactView, AddressLinkView
from rest_framework import routers
from django.contrib.auth import views as auth_views
from rest_framework.authtoken.views import obtain_auth_token


router = routers.DefaultRouter()
router.register(r'phones',AdminContactView, basename='phone')
router.register(r'addresses',AddressLinkView, basename='addresses')
router.register(r'contact',ContactAPIView, basename='contact')
router.register(r'',ProfileView, basename='profile')

 
urlpatterns = [
     # path('auth-token/', obtain_auth_token, name='token-auth'),
     path('api-auth/', include('rest_framework.urls')),

     path('password-reset/',
          auth_views.PasswordResetView.as_view(),
          name='password_reset'),
     path('password-reset/done/',
          auth_views.PasswordResetDoneView.as_view(
               template_name='password_reset_done.html'
          ),
          name='password_reset_done'),
     path('password-reset-confirm/<uidb64>/<token>/',
          auth_views.PasswordResetConfirmView.as_view(),
          name='password_reset_confirm'),
     path('password-reset-complete/',
          auth_views.PasswordResetCompleteView.as_view(),
          name='password_reset_complete'),
]

urlpatterns += router.urls

в моем django_project/settings.py:

import os
from pathlib import Path
from django.utils.translation import gettext_lazy as _  #for multi-language


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'secret key hidden'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ["*",]

# Application definition

INSTALLED_APPS = [

    'modeltranslation',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    
    'accounts.apps.AccountsConfig',
    'my_works.apps.MyWorksConfig',
    
    'crispy_forms',
    'rest_framework',
    
    'django_filters',
    'rest_framework.authtoken',
    'corsheaders',
    'phonenumber_field',
    'drf_yasg',
    'whitenoise',

]
Вернуться на верх