Get the name or URL of the app

Does anyone know a way to get the name or the URL of the app?

I have a Users table shared across many apps. Some of the apps allow users to toggle email notifications on and off. I’d like to maintain a list of app names or URLs from which the user would like to get notifications.

I have tried anvil.server.get_api_origin(). Is that what you would recommend?

1 Like

try -

anvil.server.get_app_origin()

in a server module.

Note you will get a different result in your IDE than you will from a published app accessed by its own url from a browser.

2 Likes

Ahh, so close. Thanks David.

There is also app.id which returns a string ID to your app (the ID is also in the URL of course). With a custom domain name, the get_app_origin method will likely be more human readable if that is of value.

@david.wylie

Hey David, does it make sense to you that anvil.server.get_app_origin() returns None when a function on the server is called via Uplink?

I didn’t know that it wouldn’t work, but I can reverse engineer why that might be the case - the uplink code is not running on the Anvil server, so the app origin might not make sense in that context.

I would create a server function running on Anvil that returns the app origin, and call that function from your uplink code. A bit convoluted but it should work.

1 Like

Great idea! Thanks David.