2👍
✅
Splitting
You can do something like this:
first_part = response_html.split("</style>")[0] + "</style>"
second_part = response_html.split("</style>")[1]
And then have both first_part and second_part available as template context variables
return render(request, "book.html", {
"style_section": first_part,
"content_section": second_part,
"reviews_widget": reviews_widget,
})
Rendering as HTML rather than as string
You can use mark_safe to get it to display as rendered HTML in the template. Consider carefully if you’re able to do this as it could be a security risk if you don’t trust the source of the data (GoodReads is a pretty safe bet, but its worth considering depending on how watertight your application needs to be)
<html>
<head>
{{ style_section|safe }}
</head>
<body>
{{ content_section|safe }}
</body>
</html>
Source:stackexchange.com