In the context of template variable interpolation i.e. `{{ }}`
    syntax, it is defined that `x` in this case will get converted to
    the empty string (or your 'string_if_invalid' setting) -
    - unlike the case for `if` tags.

    When this value (the empty string) is passed to `default_if_none`,
    the value is not changed, since it is not None. See

The missing piece of information for me (and even reading the docs it's far from obvious) is that undefined variables mean two different things in the different contexts.

The value *is* changed in the second case, because it *is* None. Undefined values are '' in {{ }} context but are None in {% %} context. Maybe that's obvious to you, but it's not to me. In fact, after a few minutes searching I still can't find where this is mentioned in the documentation. Only the vague statement that invalid variables are "generally" replaced with string_if_invalid.

I meant above that in the {{ }} context 'default_if_none' doesn't return the default value, but just returns the empty string input value.

I also had to read the docs to understand the behaviour - it is mentioned in the 3rd paragraph down in the docs linked above, "How invalid variables are handled" - the `if`, `for` and `regroup` tags are specifically mentioned. I think the docs could be clearly about how things work with variables passed to template tags etc. "In general" as you say is rather vague. Definitely room for improvement here!


You received this message because you are subscribed to the Google Groups "Django 
developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

Reply via email to