Django project base template

heri0n picture heri0n · Feb 6, 2013 · Viewed 48.7k times · Source

Can I create a base template for my project which all apps can draw from? Or do I have to create a base template for each app? And if I wanted them to be the same I'd just copy them?

Answer

Kenny Shen picture Kenny Shen · Feb 6, 2013

Sure you can. A quick example of a base.html

<!DOCTYPE html>
<html>
    <head>
        <title>My Project</title>
    </head>

    <body>
    {% block content %}{% endblock content %}
    </body>
</html>

And say you have a app called myapp with a view.html page,

{% extends "base.html" %}

{% block content %}
    <h2>Content for My App</h2>
    <p>Stuff etc etc.</p>
{% endblock content %}

Take some time to read the docs for more information