Context variable Processors does not work with render_to_string

Asked

Viewed 11 times

0

In some places on my system, I rescan a page with render_to_string, because I want to render only a small content. In these cases I do not receive my variables that I created in context_processors. Does anyone have a solution other than manually passing the variable in the render_to_string? Thank you.

updating

After a good search I found that in previous versions of Django (I found in version 1.9) there was a parameter in render_to_string called context_instance, where I passed the Requestcontext and it already loaded the dictionary with the context_processors variables. But for some reason it was removed from the new versions. I still don’t have a solution to load the context_processors in the render_to_string. I really need the string containing the HTML loaded with my conditions that use some variables from the context_processors. So still my problem persists.

1 answer

0

I believe it would be enough for you to do:

html_body = render_to_string(template_name, context, request=request)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.