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.generic.base.ContextMixin.get_context_data()

get_context_data(**kwargs) Returns a dictionary representing the template context. The keyword arguments provided will make up the returned context. Example usage: def get_context_data(self, **kwargs): context = super(RandomNumberView, self).get_context_data(**kwargs) context['number'] = random.randrange(1, 100) return context The template context of all class-based generic views include a view variable that points to the View instance. Use alters_data where appropriate Note th

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_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.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.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.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.decorators.vary.vary_on_cookie()

vary_on_cookie(func) [source]

views.decorators.http.require_GET()

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