1

Currently, I have the following code:

from django.shortcuts import render
# ...
def prerender(js: json) -> str:
    # ...
    response = render(None, 'partial/name.html', context)
    return response.content.decode()

Is there a way in Django to render to a string rather than to the bytes of HttpResponse? Otherwise, how to get HttpResponse content as a string properly?

1 Answer 1

3

The answer is almost in your question:

from django.template.loader import render_to_string

return render_to_string("partial/home.html", context)

You can use this to render all kinds of templates, for emails and so on.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.