I’m using Django (and Python) for the first time, and I’m looking for the correct solution to an included template that may or may not have been provided with a value.
For example, this template will always have a ‘company’ defined, but it might not always have a ‘user’ defined. If the ‘user’ is not defined, then one should be defined, like so:
<% with guy=(user if user != None else company.admin_user) %>
But I haven’t found a good way to accomplish this. In some cases a user will be defined by the includer of the template, in other cases the template should have to find a ‘default’ user.
Edit: The solution, as per Ignacio’s answer, is this:
<% with guy=user|default:company.admin_user %>
You want the
defaultfilter.