I'm trying to create the custom 404.html page for the HTTP 404
error.
For this url 127.0.0.1:8000/polls/Books/dsfdsf/
it is showing the Page not found (404)
default debugging page, while DEBUG=True
.
For same url i want to create custom 404 page.
i have gone through the Django Docs for this.
Following steps i have taken:
1). DEBUG=False
in settings.py
2). handler404 = 'pollsite.views.custom_404'
in urls.py
3). views.py
def custom_404(request):
return render('404.html', context_instance=RequestContext(request))
4). i have placed the 404.html
file in template directory , TEMPLATE_DIRS
now i expect the custom error page 404.html
to appear when i tries to access 127.0.0.1:8000/polls/Books/dsfdsf, right?
Instead i'm getting the TemplateDoesNotExist: 500.html
Even valid url showing the TemplateDoesNotExist: 500.html
Why it is not generating HTTP 404 error, and thereby invoking custom 404.html
file ?
I tried solution mentioned for question1, and question2
but still geting annoying error TemplateDoesNotExist: 500.html
please point out what is the issue?
EDIT: stacktarce of error
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
response = self.get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 153, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 228, in handle_uncaught_exception
return callback(request, **param_dict)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py", line 91, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/defaults.py", line 32, in server_error
t = loader.get_template(template_name) # You need to create a 500.html template.
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 145, in get_template
template, origin = find_template(template_name)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 138, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist: 500.html
.........................Solution:
1) in settings.py set ALLOWED_HOSTS = ['127.0.0.1']
2) in views.py return render_to_response('404.html')