Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
2f615b10
Kaydet (Commit)
2f615b10
authored
Haz 15, 2015
tarafından
ana-balica
Kaydeden (comit)
Tim Graham
Haz 17, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24829 -- Allowed use of TemplateResponse in view error handlers.
üst
64a4211a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
0 deletions
+44
-0
base.py
django/core/handlers/base.py
+9
-0
1.9.txt
docs/releases/1.9.txt
+4
-0
test_handler.html
tests/handlers/templates/test_handler.html
+1
-0
tests_custom_error_handlers.py
tests/handlers/tests_custom_error_handlers.py
+30
-0
No files found.
django/core/handlers/base.py
Dosyayı görüntüle @
2f615b10
...
...
@@ -113,6 +113,9 @@ class BaseHandler(object):
urlconf
=
settings
.
ROOT_URLCONF
urlresolvers
.
set_urlconf
(
urlconf
)
resolver
=
urlresolvers
.
RegexURLResolver
(
r'^/'
,
urlconf
)
# Use a flag to check if the response was rendered to prevent
# multiple renderings or to force rendering if necessary.
response_is_rendered
=
False
try
:
response
=
None
# Apply request middleware
...
...
@@ -174,6 +177,7 @@ class BaseHandler(object):
"HttpResponse object. It returned None instead."
%
(
middleware_method
.
__self__
.
__class__
.
__name__
))
response
=
response
.
render
()
response_is_rendered
=
True
except
http
.
Http404
as
exc
:
logger
.
warning
(
'Not Found:
%
s'
,
request
.
path
,
...
...
@@ -246,6 +250,11 @@ class BaseHandler(object):
response
.
_closable_objects
.
append
(
request
)
# If the exception handler returns a TemplateResponse that has not
# been rendered, force it to be rendered.
if
not
response_is_rendered
and
callable
(
getattr
(
response
,
'render'
,
None
)):
response
=
response
.
render
()
return
response
def
handle_uncaught_exception
(
self
,
request
,
resolver
,
exc_info
):
...
...
docs/releases/1.9.txt
Dosyayı görüntüle @
2f615b10
...
...
@@ -385,6 +385,10 @@ Requests and Responses
* The default 40x error views now accept a second positional parameter, the
exception that triggered the view.
* View error handlers now support
:class:`~django.template.response.TemplateResponse`, commonly used with
class-based views.
Tests
^^^^^
...
...
tests/handlers/templates/test_handler.html
0 → 100644
Dosyayı görüntüle @
2f615b10
Error handler content
tests/handlers/tests_custom_error_handlers.py
0 → 100644
Dosyayı görüntüle @
2f615b10
from
django.conf.urls
import
url
from
django.core.exceptions
import
PermissionDenied
from
django.template.response
import
TemplateResponse
from
django.test
import
SimpleTestCase
,
override_settings
def
template_response_error_handler
(
request
,
exception
=
None
):
return
TemplateResponse
(
request
,
'test_handler.html'
,
status
=
403
)
def
permission_denied_view
(
request
):
raise
PermissionDenied
urlpatterns
=
[
url
(
r'^$'
,
permission_denied_view
),
]
handler403
=
template_response_error_handler
@override_settings
(
ROOT_URLCONF
=
'handlers.tests_custom_error_handlers'
)
class
CustomErrorHandlerTests
(
SimpleTestCase
):
def
test_handler_renders_template_response
(
self
):
"""
BaseHandler should render TemplateResponse if necessary.
"""
response
=
self
.
client
.
get
(
'/'
)
self
.
assertContains
(
response
,
'Error handler content'
,
status_code
=
403
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment