What I’m trying to do:
I’m trying to redirect someone from one form to another if they’re not logged in. It’s so that the user can’t read the data until they’re logged in.
What I’ve tried and what’s not working:
class Home(HomeTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
anvil.users.logout()
self.logged_in = anvil.users.get_user()
if self.logged_in is None:
print("NONE WTH")
open_form(Login())
print("huh")
# Any code you write here will run when the form opens.
def text_box_1_pressed_enter(self, **event_args):
"""This method is called when the user presses Enter in this text box"""
pass
Literally new here and this is all my code; if the user isn’t logged in, they redirect to the Login page which tells them why they should log in first. All my prints are being printed.
You know it’s funny, I don’t think I have ever tried to open another form in the __init__ of a form that is loading. I have always had it set to a button or some kind of event.
I don’t think you can do that.
I moved it to a timer component that I set to stop running if it does not need to go to the next form once.
Also you can call open form with a string of the form name, you don’t have to import it as an object. (The auto-completer for open_form() should bring up available forms.)