400 error handler. Templates: :template:`400.html` Context: None
(request, exception, template_name=ERROR_400_TEMPLATE_NAME)
| 101 | |
| 102 | @requires_csrf_token |
| 103 | def 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 |