13

I have created a template for the 500 HTTP error.

I have inserted my template 500.html in:

  1. /project/
  2. /project/templates/
  3. /python2.5/
  4. /python2.5/templates/

but I always get this error:

TemplateDoesNotExist: 500.html

I get the same problem for an HTTP 404 error.

Why?

Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
xRobot
  • 25,579
  • 69
  • 184
  • 304

3 Answers3

11

You might need to specify the template directories in settings.py, if you haven't already.

e.g. in my settings.py, I have:

ROOTDIR = os.path.abspath(os.path.dirname(__file__)) 
TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    ROOTDIR + '/logistics/templates',
)
kafuchau
  • 5,573
  • 7
  • 33
  • 38
  • 1
    First, try adding this to your template_dirs: C:\Python25\Lib\site-packages\django\contrib\admin\templates\admin and see if that loads the default Django templates at all... And, if it does, then you're not specifying your dirs correctly. Note: my python instance and installed at C:\, change the path to whatever is right for your system. – kafuchau May 12 '10 at 20:58
5

Try to set
DEBUG=True in your settings file

Maria Sakharova
  • 1,389
  • 15
  • 15
  • 24
    Definitely not on a production machine. – nisc Nov 04 '11 at 17:38
  • But on a devel machine it's quite useful. I couldn't remember why I didn't get debug messages anymore, so this hint is rather helpful. Thanks! :) – Oszkar Feb 03 '12 at 19:32
  • Normally this error occurs once setting up the installation the first time, by which you probably don't have lots of traffic. The standard error logging only helps you so much. – Jonatan Littke Apr 02 '12 at 12:34
  • Debug True at least said something more to fix the bug, thanks a lot! – Coconut Oct 30 '13 at 14:02
0

You need to update your "Templates" configuration in your setting file like the below: enter image description here

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['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',
            ],
        },
    },
]

Worked for me.

  • Hi @Abiola thanks for giving a look at this, but we believe how it would help is by providing relevant reference or sample. – Surya Bhusal Jun 21 '23 at 08:24
  • 1
    @SuryaBhusal, see the updated solution above. "DIRS": is usually empty for new projects, so update it to properly point in the right folder for Django to find your templates. – Abiola Akinwoleola Jun 22 '23 at 09:24