views.defaults.server_error()

defaults.server_error(request, template_name='500.html') Similarly, Django executes special-case behavior in the case of runtime errors in view code. If a view results in an exception, Django will, by default, call the view django.views.defaults.server_error, which either produces a very simple “Server Error” message or loads and renders the template 500.html if you created it in your root template directory. The default 500 view passes no variables to the 500.html template and is rendered w

views.defaults.permission_denied()

defaults.permission_denied(request, exception, template_name='403.html') In the same vein as the 404 and 500 views, Django has a view to handle 403 Forbidden errors. If a view results in a 403 exception then Django will, by default, call the view django.views.defaults.permission_denied. This view loads and renders the template 403.html in your root template directory, or if this file does not exist, instead serves the text “403 Forbidden”, as per RFC 7231#section-6.5.3 (the HTTP 1.1 Specific

views.defaults.page_not_found()

defaults.page_not_found(request, exception, template_name='404.html') When you raise Http404 from within a view, Django loads a special view devoted to handling 404 errors. By default, it’s the view django.views.defaults.page_not_found(), which either produces a very simple “Not Found” message or loads and renders the template 404.html if you created it in your root template directory. The default 404 view will pass two variables to the template: request_path, which is the URL that resulted

views.defaults.bad_request()

defaults.bad_request(request, exception, template_name='400.html') When a SuspiciousOperation is raised in Django, it may be handled by a component of Django (for example resetting the session data). If not specifically handled, Django will consider the current request a ‘bad request’ instead of a server error. django.views.defaults.bad_request, is otherwise very similar to the server_error view, but returns with the status code 400 indicating that the error condition was the result of a cli

views.decorators.vary.vary_on_headers()

vary_on_headers(*headers) [source] The Vary header defines which request headers a cache mechanism should take into account when building its cache key. See using vary headers.

views.decorators.vary.vary_on_cookie()

vary_on_cookie(func) [source]

views.decorators.http.require_safe()

require_safe() Decorator to require that a view only accepts the GET and HEAD methods. These methods are commonly considered “safe” because they should not have the significance of taking an action other than retrieving the requested resource. Note Web servers should automatically strip the content of responses to HEAD requests while leaving the headers unchanged, so you may handle HEAD requests exactly like GET requests in your views. Since some software, such as link checkers, rely on HEA

views.decorators.http.require_POST()

require_POST() Decorator to require that a view only accepts the POST method.

views.decorators.http.require_http_methods()

require_http_methods(request_method_list) [source] Decorator to require that a view only accepts particular request methods. Usage: from django.views.decorators.http import require_http_methods @require_http_methods(["GET", "POST"]) def my_view(request): # I can assume now that only GET or POST requests make it this far # ... pass Note that request methods should be in uppercase.

views.decorators.http.require_GET()

require_GET() Decorator to require that a view only accepts the GET method.