I am testing for the availability of an attribute in an object called “url”. Django template evaluates {% if object.url %} to be False or unavailable whereas the attribute exists. object.url evaluates to a string path in a django shell.
Is it possible that django disagrees with the attribute name (i.e. url) since there is also an url tag?: e.g. {% url xxx %} What am I missing?
This can only be determined within the view that is rendering this template. That view is responsible for ensuring something named object is in the context when the template is rendered. So you’ll need to check the view in order to identify a potential cause.
(The attribute name has nothing to do with this issue, that name is used by a strict lookup sequence as defined at Variables)
Does this object’s url contain anything, or is it an empty string? Because {% if object.url %} will evaluate to false if object.url is an empty string. It isn’t testing whether the attribute exists.
One of the following is the problem:
. You passed an object with the name “object” that is different from what you expected.
. There is no attribute called “url” in the passed object.
. “object” was overwritten in the template.
If you check that the url attribute exists in the shell, in my experience, it is most likely a problem overwritten in the template.
If there is no attribute called url, none should be returned(it would be blank in rendered template), but if false is returned, it is likely that a different object is being used.