def page_not_found(request, template_name='404.html'):
context = {
'request_path': request.path,
'error': {
'title': _('Page not found'),
'message': _("We tried but couldn't find this page, sorry."),
},
}
try:
template = loader.get_template(template_name)
body = template.render(context, request)
content_type = None
except TemplateDoesNotExist:
template = Engine().from_string(
'<h1>Not Found</h1>'
'<p>The requested URL {{ request_path }} was not found on this server.</p>')
body = template.render(Context(context))
content_type = 'text/html'
return HttpResponseNotFound(body, content_type=content_type)
评论列表
文章目录