Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not fail invalid template variables with default filter #922

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jcushman
Copy link

As proposed in #471, here is an update to --fail-on-template-vars that causes missing template variables to be ignored if they use the default filter, like {{ does_not_exist|default:"ok" }}.

This is a common and documented idiom in Django, so --fail-on-template-vars is more useful if it doesn't fail in that situation. I most recently ran into this because the django-pipeline package uses {{ media|default:"all" }} in one of its templates without defining media, so --fail-on-template-vars is currently incompatible with django-pipeline.

Another common example would be a view like render('my_page.html') with the base template <title>{{ title|default:"My Site" }}</title>. It's not helpful to require each page that doesn't override title to be called as render('my_page.html', {'title': None}) -- that's the point of providing a default.

@codingjoe seemed unsure how messy this would be to implement, so I thought it might be useful to see an implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant