DEV Community

Phansivang
Phansivang

Posted on

Django handle 404 Page not found

views.py

def page_not_found_view(request, exception):
    return render(request, 'app/404.html', status=404)
Enter fullscreen mode Exit fullscreen mode

urls.py in main project folder

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('users.urls')),
    path('',include('app.urls')),

]

handler404 = "yournameapp.views.page_not_found_view"

Enter fullscreen mode Exit fullscreen mode

settings.py

import os

DEBUG = False

TEMPLATES = [
    {
        'BACKEND': 
        'DIRS': [os.path.join(BASE_DIR, 'templates')],

            ],
        },
    },
]

Enter fullscreen mode Exit fullscreen mode

Top comments (0)