Reputation: 27796
What is the most reusable way for the "extends" method in django templates?
I have seen this very often:
{% extends 'base.html' %}
Unfortunately this does not work for me. The ordering of the template loader loads a template from a different app first.
I have a default django project and application created from scratch with Django1.8.
What should I do:
Upvotes: 0
Views: 400
Reputation: 174614
The easy way to solve this problem is to namespace your templates. Create an application and inside the application directory (where you have the default views.py
) create a templates directory, and inside that directory create a subdirectory which is the name of the application.
Imagine you have a project myproj
and an app called registration, then you would have:
.
├── manage.py
├── myproj
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── registration
├── admin.py
├── __init__.py
├── migrations
│ └── __init__.py
├── models.py
├── templates
│ └── registration
│ └── base.html
├── tests.py
└── views.py
Now even if you have another application with a template called base.html
, you can always load the specific template you need with {% extends 'registration/base.html' %}
Upvotes: 1