#24829: TemplateView raises unhandled ContentNotRenderedError error when used as
handler403
-------------------------------+--------------------
     Reporter:  nonZero        |      Owner:  nobody
         Type:  Bug            |     Status:  new
    Component:  Generic views  |    Version:  1.8
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 When using TemplateView for handler403, an unhandled error occurs:


 {{{
 from django.conf.urls import url
 from django.core.exceptions import PermissionDenied
 from django.views.generic import TemplateView


 class PermissionDeniedView(TemplateView):
     template_name = '403.html'


 handler403 = PermissionDeniedView.as_view()


 def my_view(request):
     raise PermissionDenied


 urlpatterns = [
     url(r'^$', my_view),
 ]
 }}}

 Traceback:


 {{{
 Traceback (most recent call last):
   File "/usr/lib64/python2.7/wsgiref/handlers.py", line 86, in run
     self.finish_response()
   File "/usr/lib64/python2.7/wsgiref/handlers.py", line 127, in
 finish_response
     for data in self.result:
   File "/home/foo/.virtualenvs/bar/lib/python2.7/site-
 packages/django/template/response.py", line 171, in __iter__
     raise ContentNotRenderedError('The response content must be '
 ContentNotRenderedError: The response content must be rendered before it
 can be iterated over.
 [20/May/2015 07:26:25]"GET / HTTP/1.1" 500 59
 Traceback (most recent call last):
   File "/usr/lib64/python2.7/SocketServer.py", line 599, in
 process_request_thread
     self.finish_request(request, client_address)
   File "/usr/lib64/python2.7/SocketServer.py", line 334, in finish_request
     self.RequestHandlerClass(request, client_address, self)
   File "/home/foo/.virtualenvs/bar/lib/python2.7/site-
 packages/django/core/servers/basehttp.py", line 102, in __init__
     super(WSGIRequestHandler, self).__init__(*args, **kwargs)
   File "/usr/lib64/python2.7/SocketServer.py", line 655, in __init__
     self.handle()
   File "/home/foo/.virtualenvs/bar/lib/python2.7/site-
 packages/django/core/servers/basehttp.py", line 182, in handle
     handler.run(self.server.get_app())
   File "/usr/lib64/python2.7/wsgiref/handlers.py", line 92, in run
     self.close()
   File "/usr/lib64/python2.7/wsgiref/simple_server.py", line 33, in close
     self.status.split(' ',1)[0], self.bytes_sent
 AttributeError: 'NoneType' object has no attribute 'split'
 }}}

 One workaround is to force TemplateResponse to render itself:


 {{{
 class PermissionDeniedView(TemplateView):
     template_name = '403.html'

     def dispatch(self, request, *args, **kwargs):
         response = super(PermissionDeniedView, self).dispatch(request,
 *args, **kwargs)
         response.render()
         return response
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24829>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.6c20810e6fa594aeef5afe979514bc3e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to