Answer the question
In order to leave comments, you need to log in
handler404 not working, why?
Who can explain why handler404 does not work?
The main urls.py of the project:
import project.settings
from django.conf.urls import include, url
from django.contrib import admin
handler404 = 'project.views.handler404'
urlpatterns = [
url(r'^$', include('apps.main.urls')),
url(r'^quote/', include('apps.quote.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^media/(.*)$', 'django.views.static.serve', {'document_root': project.settings.MEDIA_ROOT}),
]
from django.shortcuts import render
def handler404(request):
return render(request, '../templates/errors/404.html', status=404)
Answer the question
In order to leave comments, you need to log in
What's the error?
Usually, the path to the template does not include the templates folder and the tembole ../ at the beginning.
settings.py
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
},
]
def handler404(request):
return render(request, 'errors/404.html', status=404)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, "templates"),
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question