Understanding Django templates
Every web framework needs a way to generate full HTML pages. In Django, we use templates
to serve individual HTML files. In the movie
folder, create a folder called templates
. Each app should have its own templates folder (Figure 4.1).
In the course of this book, you will see a pattern repeatedly in Django development – templates, views, and URLs. We have already worked with views and URLs in the previous chapter. The order between them doesn't matter, but all three are required and work closely together. Let's implement the template and refined view for the home page.
Template
In /movie/templates/
, create a new file, home.html
. This will be the full HTML page for the home page. For now, fill it in with the following:
<!DOCTYPE html> <html> <head> <title>Movies App</title> <...