Are <html> tags needed in templates?

Do I need to include the HTML <!DOCTYPE> and the root tags in django templates?
In the tutorial it shows just the body’s content in the templates:


<h1>{{ question.question_text }}</h1>
{% for choice in question.choice_set.all %}
    <li>{{ choice.choice_text }}</li>
{% endfor %}

Is the “<!doctype html>” and “<html></html>” omitted for brevity, or does django automatically add it?

You can find out yourself by going to ‘View Source’ in the browser :slight_smile: But no, Django doesn’t add anything automatically - only what you tell it to. So it’s omitted for brevity.

FWIW If you omit the <!DOCTYPE html> at the beginning an HTML file you will trigger quirks mode in the browser, which is a leftover from a previous age of web browsers. In a demo like this it doesn’t make a difference, but in general you don’t want that behaviour! So you should always include it in an HTML file.

1 Like

I’ve made a pull request to add a note to the tutorial:

1 Like

This has been merged :slight_smile: