Modular templates in django
django, html, python, templates
Solution
Instead of using `{% load 'menu.html' %}` you have to use `{% include 'menu.html' %}`
Docs:
- include
- load
Problem
I am getting started with Django, and I'm trying to make a modular template, but I don't know how. Now, I have the following files: 1- base.html (which provides basic layout for all the website): ``` {% load staticfiles %} <!DOCTYPE html> <html> <head> <title>My site</title> <link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}" /> <link rel="stylesheet" type="text/css" href="{% static 'css/bootsrap.min.css' %}" /> </head> <body> <h1>Test title</h1> {% block content %} {% endblock %} </body> </html> ``` 2- index.html (main db read) ``` {% extends 'base.html' %} {% block content %} {% if latest_smartphones_list %} <ul> {% for s in latest_smartphones_list %} <li><a href="#">{{ s.brand }} {{ s.name }}</a></li> {% endfor %} </ul> {% else %} <p>No smarphones available.</p> {% endif %} {% endblock %} ``` Finally, i wanted to add a third file, called menu.html which would contain the site menu. I wanted to add it in the base.html file. I've been thinking about doing it in the following way, but i doesn't work: ``` {% load 'menu.html' %} ``` Thanks so much for your help!