diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-08-04 11:01:01 +0200 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2013-08-04 11:04:37 +0200 |
| commit | 784377544e01322b0d09e5cf4e8f6dda159df854 (patch) | |
| tree | 5722c511e8f5d0fb3c99653e2e82740faa673fc5 /django/views/defaults.py | |
| parent | 0bcdcc7eb9ca2265cb83225257df65a8def3e14a (diff) | |
Fixed #20822 -- Set content type of default error pages to 'text/html'.
Thanks Jimmy Song for the patch.
Diffstat (limited to 'django/views/defaults.py')
| -rw-r--r-- | django/views/defaults.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/django/views/defaults.py b/django/views/defaults.py index e9d0f16a33..2f54fcd263 100644 --- a/django/views/defaults.py +++ b/django/views/defaults.py @@ -21,11 +21,14 @@ def page_not_found(request, template_name='404.html'): """ try: template = loader.get_template(template_name) + content_type = None # Django will use DEFAULT_CONTENT_TYPE except TemplateDoesNotExist: template = Template( '<h1>Not Found</h1>' '<p>The requested URL {{ request_path }} was not found on this server.</p>') - return http.HttpResponseNotFound(template.render(RequestContext(request, {'request_path': request.path}))) + content_type = 'text/html' + body = template.render(RequestContext(request, {'request_path': request.path})) + return http.HttpResponseNotFound(body, content_type=content_type) @requires_csrf_token @@ -39,7 +42,7 @@ def server_error(request, template_name='500.html'): try: template = loader.get_template(template_name) except TemplateDoesNotExist: - return http.HttpResponseServerError('<h1>Server Error (500)</h1>') + return http.HttpResponseServerError('<h1>Server Error (500)</h1>', content_type='text/html') return http.HttpResponseServerError(template.render(Context({}))) @@ -54,7 +57,7 @@ def bad_request(request, template_name='400.html'): try: template = loader.get_template(template_name) except TemplateDoesNotExist: - return http.HttpResponseBadRequest('<h1>Bad Request (400)</h1>') + return http.HttpResponseBadRequest('<h1>Bad Request (400)</h1>', content_type='text/html') return http.HttpResponseBadRequest(template.render(Context({}))) @@ -75,7 +78,7 @@ def permission_denied(request, template_name='403.html'): try: template = loader.get_template(template_name) except TemplateDoesNotExist: - return http.HttpResponseForbidden('<h1>403 Forbidden</h1>') + return http.HttpResponseForbidden('<h1>403 Forbidden</h1>', content_type='text/html') return http.HttpResponseForbidden(template.render(RequestContext(request))) |
