Installation¶
Create a new Django project or
cdto an existing projectpip install dj-anglesEdit
TEMPLATES.loadersinsettings.py. Note: you might need to removeAPP_DIRSand addOPTIONS.loaderssince it is not there by default (https://docs.djangoproject.com/en/stable/ref/templates/api/#django.template.loaders.cached.Loader).
# settings.py
from dj_angles import get_template_loaders
...
TEMPLATES = [{
"BACKEND": "django.template.backends.django.DjangoTemplates",
# "APP_DIRS": True, # this cannot be specified if OPTIONS.loaders is explicitly set
"DIRS": [],
"OPTIONS": {
"context_processors": [
"django.template.context_processors.request",
"django.template.context_processors.debug",
"django.template.context_processors.static",
],
"loaders": get_template_loaders(),
},
}]
Note
get_template_loaders returns a list of template loaders to enable dj-angles. It automatically handles caching templates when DEBUG=False and integrates django-components, django-viewcomponent, django-bird, and django-template-partials template loaders if they are installed.
Middleware¶
dj-angles includes middleware for checking the request method and whether the request is AJAX.
# settings.py
...
MIDDLEWARE = [
...
"dj_angles.middleware.RequestMethodMiddleware",
"dj_angles.middleware.RequestAJAXMiddleware",
]
Scripts¶
Add scripts for custom elements.
<!-- base.html -->
{% load dj_angles %}
{% dj_angles_scripts %}