mirror of
https://github.com/django/django.git
synced 2024-12-26 11:06:07 +00:00
40cb11a554
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9001 bcc190cf-cafb-0310-a4f2-bffc1f526a37
36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
from django import http
|
|
from django.template import Context, RequestContext, loader
|
|
|
|
def page_not_found(request, template_name='404.html'):
|
|
"""
|
|
Default 404 handler.
|
|
|
|
Templates: `404.html`
|
|
Context:
|
|
request_path
|
|
The path of the requested URL (e.g., '/app/pages/bad_page/')
|
|
"""
|
|
t = loader.get_template(template_name) # You need to create a 404.html template.
|
|
return http.HttpResponseNotFound(t.render(RequestContext(request, {'request_path': request.path})))
|
|
|
|
def server_error(request, template_name='500.html'):
|
|
"""
|
|
500 error handler.
|
|
|
|
Templates: `500.html`
|
|
Context: None
|
|
"""
|
|
t = loader.get_template(template_name) # You need to create a 500.html template.
|
|
return http.HttpResponseServerError(t.render(Context({})))
|
|
|
|
def shortcut(request, content_type_id, object_id):
|
|
# TODO: Remove this in Django 2.0.
|
|
# This is a legacy view that depends on the contenttypes framework.
|
|
# The core logic was moved to django.contrib.contenttypes.views after
|
|
# Django 1.0, but this remains here for backwards compatibility.
|
|
# Note that the import is *within* this function, rather than being at
|
|
# module level, because we don't want to assume people have contenttypes
|
|
# installed.
|
|
from django.contrib.contenttypes.views import shortcut as real_shortcut
|
|
return real_shortcut(request, content_type_id, object_id)
|