Hi,
I may be doing something wrong or maybe this has been answered before but I wasn’t able to find anything related to my problem.
I want to create a form that checks if the user is logged in and redirects him to a new form before the elements on the first one load or, if the user is not logged in, perform the log in with a button and automatically redirect him to the new form if the login was successful.
The first question I have is how to redirect the user right after logging in with the anvil.users.login_with_form() method?
The second issue that I am facing is navigating to a new form with open_form before loading any elements.
I tried to test it and whenever the form is located inside a event handler like a click method, it correctly opens the new form and logs the message that it was opened.
If I call the open_form method on the initialization phase or outside an event handler, it logs the message that the new form was opened but nothing changes and I am still in the first form. I even tried to create a method for it.
Do you have any suggestions?
Here is the code:
class Home(HomeTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
if anvil.users.get_user():
self.navigate_to_main()
print("User already logged in.")
def navigate_to_main(self):
open_form('Test')
pass
def logIn_button_click(self, **event_args):
"""This method is called when the button is clicked"""
anvil.users.login_with_form()
#open_form('Test') - this is where I want to redirect the user after logging in
pass
def link_logout_click(self, **event_args):
"""This method is called when the link is clicked"""
print("Logging Out")
anvil.users.logout()
pass
The Test form only has a starting print and a label inside it.
Thank you!