From b8ff4d135e26a6b43f86ac0bc4c24cb5a28d09a2 Mon Sep 17 00:00:00 2001 From: authcode Date: Mon, 15 Nov 2021 15:31:45 +0000 Subject: [PATCH] Fixed render bugs in render_to_temporary_file No version of template render() has ever accepted a request argument, or a dict context. Conversely, render_to_string does accept an optional request kwarg. --- wkhtmltopdf/utils.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index e14d3c2..330153f 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -314,20 +314,17 @@ def render_to_temporary_file(template, context, request=None, mode='w+b', try: render = template.render except AttributeError: - content = loader.render_to_string(template, context) + content = loader.render_to_string(template, context, request=request) else: - if django.VERSION < (1, 8): - # If using a version of Django prior to 1.8, ensure ``context`` is an - # instance of ``Context`` - if not isinstance(context, Context): - if request: - context = RequestContext(request, context) - else: - context = Context(context) - # Handle error when ``request`` is None - content = render(context) - else: - content = render(context, request) + # Ensure ``context`` is an instance of ``Context`` + if not isinstance(context, Context): + if request: + context = RequestContext(request, context) + else: + context = Context(context) + + content = render(context) + content = smart_text(content) content = make_absolute_paths(content)