I have some buttons that I want to be visible or invisible depending on who the current user is. My first approach was to use a data binding to the visible property. This is in a button that’s on a row of a data grid.
That first button worked wonderfully, with this code bound to the visible property:
len(self.item['players']) > 1 and anvil.users.get_user() == self.item['owner']
Then I added a second button and bound this to its visible property:
len(self.item['players']) < self.item['max_players'] and not anvil.users.get_user() in self.item['players']
That button gives an error when I run the app:
name 'anvil' is not defined
So I played around to try to work out what the difference was between the two bindings. I can confirm that something as simple as this fails with the same error message:
anvil.users.get_user()
But, if I copy my original binding from the first button, it doesn’t generate an error. Does anyone have any ideas what might be going on? What’s special about that first binding that causes it to work, when everything else I try fails? Should I be able to use anvil.users.get_user() in the way that I’m trying inside a data binding?