published by | Adam Johnson |
---|---|
in blog | Adam Johnson |
original entry | Django: The perils of string_if_invalid in templates |
Django’s template engine has a string_if_invalid
option that replaces missing variable lookups with a string of your choice:
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
# ...
"OPTIONS": {
# ...
"string_if_invalid": "MISSING VARIABLE %s",
},
}
]
The %s
will be replaced with the name of the missing variable.
This exists as a debugging aid to …