[Fixed]-Include Templates in Django. Am i doing it right?

1👍

It depends on what you need. I see 2 cases :

  • if for any reason I could have two or more base templates (like base.html and base_mobile.html, for example), which have to share some parts (like most infos), I would do this in base_mobile :
<html>
    <head>
        <script src="./static/js/mobile.js"></script>
        {% include 'include_head.html' %}
    </head>
    ...
</html>

And have the same for base.html, but without the mobile.js inclusion.

  • If the include_head is only used in one file, I see no reason not to write its content directly in that file.
<html>
    <head>
        <script src="./static/js/map.js"></script>
    </head>
    ...
</html>
👤BriceP

Leave a comment