MCPcopy
hub / github.com/django/django / bad_request

Function bad_request

django/views/defaults.py:103–122  ·  view source on GitHub ↗

400 error handler. Templates: :template:`400.html` Context: None

(request, exception, template_name=ERROR_400_TEMPLATE_NAME)

Source from the content-addressed store, hash-verified

101
102@requires_csrf_token
103def bad_request(request, exception, template_name=ERROR_400_TEMPLATE_NAME):
104 """
105 400 error handler.
106
107 Templates: :template:`400.html`
108 Context: None
109 """
110 try:
111 template = loader.get_template(template_name)
112 body = template.render(request=request)
113 except TemplateDoesNotExist:
114 if template_name != ERROR_400_TEMPLATE_NAME:
115 # Reraise if it's a missing custom template.
116 raise
117 return HttpResponseBadRequest(
118 ERROR_PAGE_TEMPLATE % {"title": "Bad Request (400)", "details": ""},
119 )
120 # No exception content is passed to the template, to not disclose any
121 # sensitive information.
122 return HttpResponseBadRequest(body)
123
124
125@requires_csrf_token

Callers 3

test_bad_requestMethod · 0.90
test_error_pagesMethod · 0.90

Calls 3

get_templateMethod · 0.45
renderMethod · 0.45

Tested by 3

test_bad_requestMethod · 0.72
test_error_pagesMethod · 0.72