Incomplete HTML in tutorials?

In the tutorials it says:

To make the tutorial shorter, all template examples use incomplete HTML. In your own projects you should use complete HTML documents.

I’m a total beginner in web development/django. What does it mean exactly that the tutorial only offers incomplete HTML? Does it mean I should make it complete for the tutorial to work? Or, does it mean it works for the tutorial but there could be subtle issues in production?

From the referenced docs, a “complete” html page has these elements:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>My test page</title>
  </head>
  <body>
    <p>This is my page</p>
  </body>
</html>

What the tutorial provides is just this part:
<p>This is my page</p>
That’s where the example template “stuff” goes from the examples - replace that line with whatever’s being shown.

This means then you’re want to have this:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>My test page</title>
  </head>
  <body>

before the template examples, and then this:

  </body>
</html>

after it.
(Oh yea, you can also change the title if you want to something else.)

1 Like

Thanks Ken!

Is there a ‘django-y’ way of choosing the title?

Daniel

Eh, not so much. The title isn’t something you see in the page, it’s what sets the title of the tab in your browser. If that’s something you want to have dynamic on different pages, you can set a value for it in the view, pass it to your template in the context, and render it in the template using the {{ }} notation, just like any other data being rendered.

1 Like