J
J
javanub2015-06-16 21:43:16
Django
javanub, 2015-06-16 21:43:16

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}),
]

the actual view from the same project folder:
from django.shortcuts import render


def handler404(request):
    return render(request, '../templates/errors/404.html', status=404)

DEBUG=True

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey K, 2015-06-17
@javanub

Disable debug mode.
DEBUG = False

A
Alexander, 2015-06-16
@syschel

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,
    },
]

views.py
def handler404(request):
    return render(request, 'errors/404.html', status=404)

settings.py
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 question

Ask a Question

731 491 924 answers to any question