1

I wanted to add custom error pages to my website, butI am getting the simple pages, for example the 403 error I am not getting the template I built. template is located in templates/http_errors/ folder.

my template settings in settings file looks like this:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [normpath(join(PROJECT_DIR, 'templates'))],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.media',
                'django.template.context_processors.i18n'
            ],
        },
    },
]

and urls.py:

from django.conf.urls import handler403
handler403 = 'core.views.custom_handler403'

and views.py:

def custom_handler403(request):
    response = render_to_response('http_errors/HTTP403.html', {},
                                  context_instance=RequestContext(request))
    response.status_code = 403
    return response

I tried a lot of options found on django docs and stackoverflow but could not still find the answer. It would be great if you helped me with this.

P.S. I am using Django 1.10 and Python 3.5

4
  • are you receiving any errors? Commented Jun 27, 2017 at 8:27
  • refer to this stackoverflow.com/a/24725091/5250746 Commented Jun 27, 2017 at 8:32
  • I am not getting any errors, HTTP403 is raised but it does not load the custom page I created Commented Jun 27, 2017 at 8:36
  • I used that topic to create the view actually Commented Jun 27, 2017 at 8:40

1 Answer 1

1

These custom pages will only work if you have DEBUG = False in your settings. Otherwise normal debug handlers will be used

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.