diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index 68034b8..45c0f82 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -314,20 +314,16 @@ 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_str(content) content = make_absolute_paths(content)