python - How to display custom 404.html page in Django -
i want display custom 404 error page when end user enters wrong url,i have tried getting django default 404 page.i using python(2.7.5),django(1.5.4)
my code
urls.py
from django.conf.urls import patterns, include, url mysite import views handler404 = views.error404 urlpatterns = patterns('', url(r'^$', 'mysite.views.home', name='home'), )
views.py
from django.http import httpresponse django.shortcuts import render django.template import context, loader def home(request): return httpresponse("welcome world") def error404(request): template = loader.get_template('404.html') context = context({'message': 'all: %s' % request,}) return httpresponse(content=template.render(context), content_type='text/html; charset=utf-8', status=404)
i have placed 404.html page in templates directory.how handle this..?
custom url handlers don't work debug=true
. set debug=false
, work. (you'll need set allowed_hosts=['127.0.0.1']
)
Comments
Post a Comment