Rendering HTML in the backend
In this chapter, we will take the first steps on the principles of HTML over WebSockets. The backend will be in charge of rendering the HTML, taking the responsibility away from JavaScript and simplifying its tasks. On the other hand, we will avoid the need to incorporate a framework such as React, Vue, or Angular, and an API for an HTTP client.
The goal will be to build a body mass index (BMI) calculator for adults using the metric system. All calculations and HTML creation will be a Django task.
All the code for the example can be found at https://github.com/PacktPublishing/Building-SPAs-with-Django-and-HTML-Over-the-Wire/tree/main/chapter-3/Rendering%20HTML.
We will ask for the height, in centimeters, and the weight, in kilograms. The formula to get it is weight (kg) / (height (m))2.
In Python, it would be translated as follows: weight / (height ** 2)
.
And its result will indicate the status:
Table 1.1 –...