Issue with Users Service and Layouts when using IDE

I have an app that I built a Layout for using the tutorial. I then create a new form and use the layout as the template. that works fine.
When i activate the users service and add

anvil.users.login_with_form()

image

to the layouts __init__ method, underneath the self.init_components(**properties) line then it doesnt allow me to view the design tab of any forms that use the layout as a template, i just get this:

but i can use the code tab and view all the code for that form.

if i want to edit anything in the form (SDVS in this example), i need to go back to the layout (Homepage) and comment out the

anvil.users.login_with_form()

image

and then the form design tab works… am i doing something wrong here?

Weird. Try something like:

if not anvil.users.get_user():
   print(“okay so far”)
   try: 
      anvil.users.login_with_form()
      print(“phew”)
   except:
      print(“gone wonky”)

Give the app a run an see what happens.

Try it first in the Layout and see what happens on a page running the Layout. Then use the code on the page using the Layout but not the layout itself.

Process of elimination.

very good point @socint ! if I put

anvil.users.login_with_form()

on the form rather than the layout template it works fine… weird indeed. But, by having it in the form it doesnt trigger the login function.
will continue to play around!

I wonder if

is interfering with the IDE’s Designer. If it’s trying to run Layout code at Design time, as happens with many Custom Components, then you can prevent that. See “as-yet-undocumented but useful feature” in:

2 Likes

What happens if you move it into form_show in the layout?

it allows me to view the design tab but doesnt present the login form. been playing around with it for a while but about to give up :joy:

What about trying the mystic route, what happens if you:

from anvil.designer import in_designer
if not in_designer:
    import anvil.users

Or something. I dunno :laughing:

1 Like

More likely:

from anvil.designer import in_designer
.
.
.

        if not in_designer:
            anvil.users.login_with_form()
2 Likes

That’s what the dark recesses of my brain meant :laughing:

1 Like

many thanks @socint @p.colbert, that worked a treat!

1 Like