Returning to a startup module

How to I return to a startup module?

When I used a landing form in the same way, I would open_form() it after logging out. Can I do the same thing with a startup module?

The startup module can be used to decide what form to show at startup. That’s better than guessing what you should show only to realize later that you needed to show another form, for example a notification to the user that they need to check the confirmation email or that they have won the lottery.

Once that form has been shown, each form will decide what to do as usual. You can have all forms sharing the same logic imported from a module, but I think the startup module is out of the picture now.

1 Like

As @stefano.menci mentions… I don’t think it’s possible to use open_form on a module.

Here’s an option though…

StartupModule

import anvil.users
from anvil import open_form

def startup():
  if not anvil.users.get_user():
    open_form('LoginForm')
  else:
    open_form("MainForm")
    

if __name__ == "__main__":
  startup()

Then when you want to use it again just import the function… This way you keep the startup logic in a Module and can reuse the code later.

def signout_button_click(self, **event_args):
  from ..StartupModule import startup
  startup()

7 Likes

That, of course, is the thing to do.

Cheers.