Hello, I am new to Python and Anvil, I would appreciate a little help to get up and running.
What I’m trying to do:
I have created another column in the user database table. I have been trying to figure out how to get it to check that column for true or false, for the current login user.
What I’ve tried and what’s not working:
I have tried so many different variations of the if line below. But obviously I haven’t got the right one That is even if I’m on the right track.
user = anvil.users.get_user()
if user['mainlink']:
form.load_component(Component_my_stuff_profile_mainlink())
else:
form.load_component(Component_home_anon())
Is your Users Data Table client-readable (that is, accessible to forms)? You’d have to change a setting in Data Tables to make it so. Then I think that code should work.
As the linked docs explain, though, this is not advisable from a security standpoint. (It would expose your users’ email addresses, etc. to potential attackers.) Instead, I would retrieve the desired information from the Users table using a server function.
The table I am using is the one Anvil creates for users which is not readable or writable in forms. Even if I change the ability to read or write it still does not work, I get the same error.
user = anvil.users.get_user()
if user is not None and user['mainlink'] is False:
form.load_component(Component_my_stuff_profile_mainlink())
elif user is not None and user['mainlink'] is True:
form.load_component(Component_my_stuff_profile())
else:
form.load_component(Component_home_anon())
if user and not user['mainlink']:
form.load_component(Component_my_stuff_profile_mainlink())
elif user and user['mainlink']:
form.load_component(Component_my_stuff_profile())
else:
form.load_component(Component_home_anon())
Thank you, I bet that makes coding a lot easier in the long run.
As a side note I didn’t even know concisely was a word. I looked up and feel smarter now.