In the first section of this chapter, we created a very simple view for our application's main page. We had to embed the HTML code of the page into the view's code. This approach has many disadvantages even for a basic view:
Good software engineering practices always emphasize the separation between UI and logic, because it enhances reusability. On the other hand, embedding HTML within the Python code clearly violates this rule.
Editing HTML embedded within Python requires Python knowledge. But this is impractical for many development teams whose web designers do not know Python.
Handling HTML code within the Python code is a tedious and error-prone task. For example, quotation marks in HTML may need to be escaped in Python strings, and the overall result may be unclean and unreadable code.
Therefore, we'd better separate Django views from HTML code generation before continuing with our application. Fortunately for us, Django provides a component...