django-apptemplates is a Django template loader that allows you to load a template from a specific application. By this you can both extend and override a template at the same time. The default Django loaders require you to copy the entire template you want to override, even if you only want to override one small block.
Based on: http://djangosnippets.org/snippets/1376/
Python 2.6 through 3.5, and Django 1.4 through 1.9 are supported (verified by tests).
This package is available from PyPI. To install it simply execute:
$ pip install django-apptemplates
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'OPTIONS': {
'loaders': [
'apptemplates.Loader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
},
},
]
TEMPLATE_LOADERS = (
'apptemplates.Loader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
Template usage example (extend and override Django admin base template):
{% extends "admin:admin/base.html" %}
The part before the colon (:
) is called the Django app namespace.
- django-app-namespace-template-loader (supports empty namespaces)
- Peter Bittner (current maintainer)
- Tomas Zulberti (former maintainer)
- Konrad Wojas (original author)
- Reestablish support for Django 1.4 through 1.8 (broken since version 1.1)
- Add tests for template rendering
- Drop support for Django 1.3 (which cannot be confirmed by tests)
- Drop support for Python 2.4 and 2.5 (which cannot be tested anymore)
- Fix
ImportError
for Django 1.8 (broken in release 1.1) - Add integration tests (test import of package across supported versions)
- Add
clean
andtest
commands tosetup.py
- Use
django.template.Origin
in computation of template location for Django 1.9 compatibility. -- Thanks, Gilles Crettenand!
- Remove Django 1.9 deprecation warning of imports
- Update README with instructions for Django 1.8+
Skipped to fix conflicting versioning in setup.py and the PyPI package
- Released as originally published on djangosnippets