David542
David542

Reputation: 110093

Rendering HTML directly without using a template

What is the simplest way to return HTML without rendering a template?

Something like:

return HttpResponse('<html><p>Hello!</p></html>')

If I just do this as above, it will render it as a string instead of html.

Upvotes: 0

Views: 73

Answers (1)

Ondrej Slint&#225;k
Ondrej Slint&#225;k

Reputation: 31910

You need to set content type to text/html:

return HttpResponse("<html><p>Hello!</p></html>", content_type="text/html")

It should be default content type unless you've set DEFAULT_CONTENT_TYPE setting to something else.

Upvotes: 5

Related Questions