Use the login form with the new Layout does not work

Hi

When I use the single line login with the Layout, I get an error.
I have the layout on the form HomePage and add the line anvil.users.login_with_form() after the init. However I cannot add any data to the forms using the Layout because of the error.

What am I missing here?

from ._anvil_designer import HomepageTemplate
from anvil import *
import anvil.server
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables
import anvil.users


class Homepage(HomepageTemplate):
    def __init__(self, **properties):
        # Set Form properties and Data Bindings.
        self.init_components(**properties)
        anvil.users.login_with_form()
        
        # Any code you write here will run before the form opens.

    def data_input_link_click(self, **event_args):
        open_form('DataInput')

    def results_link_click(self, **event_args):
        open_form('Results')

    def reset_links(self, **event_args):
        self.data_input_link.role = ''
        self.results_link.role = ''
        self.logout_link.role = ''

    def logout_link_click(self, **event_args):
        anvil.users.logout()
        open_form('Logout')

You can change it to this:

    if not in_designer:
      anvil.users.login_with_form()

and import this

from anvil.designer import in_designer

See Meredydd’s post:

3 Likes