simonw / django-openid

A modern library for integrating OpenID with Django - incomplete, but really nearly there (promise)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TemplateResponse baking happens too late

brosner opened this issue · comments

I don't think this is something django-openid should fix (since TemplateResponse might need some Django love to work correctly), but since it is included I'll just mention it here. TemplateResponse doesn't render the template until the last possible second. This has some great advantages, but disadvantages too because Django isn't aware that the HttpResponse will do this. This results in template rendering to happen in the WSGI handler outside of the base handler. As a result request.urlconf won't work since by this point it has been reverted back to ROOT_URLCONF (in Django). Furthermore any exceptions that occur during rendering bypass the base handlers lovely debug screen in DEBUG=True mode (any base handler exception handling code).

I faced a similar issue while getting the CSRF token to get evaluated to set a cookie. My fix which is hackish because it forces an evaluation of the TemplateResponse using the str (should be a unicode ideally) function to set the CSRF cookie is available at http://github.com/theju/django-openid/commit/6dbda539e306371e23ad447fb863ed33b4663060