From 99e7abd580541d6ab9d521772c44a2796a5b5f56 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 2 May 2019 11:16:01 +0200 Subject: [PATCH 1/4] utils: render authenticator response if necessary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Je sais pas pourquoi mais FormView va retourner des TemplateRespone (pas rendered) mais au moment de la redirection après un succès la réponse est déjà rendered. Ça me paraît pas terrible comme comportement donc ce fix n'est pas terrible non plus, je peux aussi le mettre au niveau du code qui en a besoin mais ça sera peut-être utile à d'autres Authenticator, du coup je l'ai mis là. --- src/authentic2/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/authentic2/utils.py b/src/authentic2/utils.py index 9d26089c..54f4a453 100644 --- a/src/authentic2/utils.py +++ b/src/authentic2/utils.py @@ -42,6 +42,7 @@ from django.utils.translation import ugettext as _, ungettext from django.utils.six.moves.urllib import parse as urlparse from django.shortcuts import resolve_url from django.template.loader import render_to_string, TemplateDoesNotExist +from django.template.response import ContentNotRenderedError from django.core.mail import send_mail from django.core import signing from django.core.urlresolvers import reverse @@ -219,7 +220,11 @@ def get_authenticator_method(authenticator, method, parameters): status_code = 200 # Some authenticator methods return an HttpResponse, others return a string if isinstance(response, HttpResponse): - content = response.content + try: + content = response.content + except ContentNotRenderedError: + response.render() + content = response.content status_code = response.status_code return { 'id': authenticator.id, -- 2.20.1