Search code examples
djangotemplatesprojectradix

Django project base template


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?


Solution

  • 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