Hi,
I’m learning anvil functionalities through tutorials. And now, i’m on the multi-users app tutorial.
I don’t understand how the login page is generated ? I suppose that it’s a predefined function built by anvil which generates a page(tell me if i’m wrong). But what i don’t understand is when it’s called. I didn’t create a homepage object so i’m a little bit confused about what the app runs.
Thank you
Hi and Welcome to the community.
You are correct that the login form is an Anvil function
and the login form is accessed by running anvil.users.login_with_form()
To use this you need the Users service enabled.
The best place to have this usually is in your start up form or module.
It’s a little hard to see what is wrong with out seeing the code. Can you share your code or better a clone link?
There is nothing wrong with the code. I’m just trying to undersand what i’m doing.
More precisely, my concern is about when the “homepage” object is created. In the previous tutorial(about the form) for example, we clearly had the submit button which calls the “button_1_click” function via the click event.
But with this tutorial, i just run the app without knowing how different elements are called. Is my question clearer ?
That’s the link : Anvil | Login
Ok I think I understand.
Having had a look at the clone I think your question could be phrased as “How does the app work with the start up form?”
If so - here is a very simple breakdown.
The Homepage is set as the Startup form, meaning that it will be the first form that is loaded when a user accesses the app. You can see that it has the lightning bolt icon indicating it is the start up form.

When this form is loaded the code in the form runs starting with the import statements:
from ._anvil_designer import HomepageTemplate
from anvil import *
import anvil.users
import anvil.server
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables
from ..ArticleEdit import ArticleEdit
The next section of code includes the __init__
function will be the first function that runs when the form is loaded.
class Homepage(HomepageTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# login/new account
anvil.users.login_with_form()
# Any code you write here will run when the form opens.
self.refresh_articles()
# Set an event handler on the RepeatingPanel (our 'articles_panel')
self.articles_panel.set_event_handler('x-delete-article', self.delete_article)
So when a user navigates to your app the __init__
function will run and on line 16 it is going to run the login_with_form()
function
Once a user has logged in and that function completes, the self.refresh_articles
function will run and them an event handler is set.
Once the __init__
function is complete the app will basically wait until another function is called from a button click or other event.
The main takeaways are that the Start up form runs first and __init__
functions run first in a form so the __init__
function in the start up form is a great place to log a user in so that it happens first up.
I am not sure that I have explained it very well so hopefully that makes some sense?
2 Likes
Thank you very much. That’s exactly what I was looking for
1 Like