Rendering HTML content
The foundation of the web is HTML. It is the media that enables browsers to function; therefore, it is fundamental that a web server is capable of delivering HTML content. Whether building a traditional page-based application or a single-page application, HTML delivery will be necessary. In Chapter 3, Routing and Intaking HTTP Requests, we discussed how we could route web requests to our static files. If you have static HTML files, then this is a great option. But what if you need to generate dynamic HTML for your application?
Since there are numerous ways that this could be accomplished, we will take a look at some of the general patterns that could be used with Sanic.
Delivering HTML files
Generally, serving HTML content is a simple operation. We need to send back a response to the client with HTML text and a header that tells the recipient that the document should be treated as HTML. Ultimately, the raw HTTP response is going to look like this:
...