Hello, hope all are fine!
I’m trying to send notification from server side, but from console i have error nomodule Notication, if it can be possible wich library i need to use?
Thank you so much!
You do not send notifications from server to client. The client makes a call to the server, the server can return results from that call, and the client then does something with those results.
The closest you can get to the server notifying the client is to have a Timer on the client that periodically calls the server to ask if there are any notifications.
That is a limitation of Anvil.
Using a timer as suggested by @jshaffstall is a simple workaround. But not very suited to quick updates and/or many clients.
A reasonable workaround, but more complex, is using MQTT. I posted this some time ago.
The use of Timer depends on your situation and there are other ways to do it too.
Can you tell us more about your use case here?
If you are calling a server function when you need to communicate back you could just return
the message?
@anvil.server.callable
def some_server_func ():
result = some_other_func()
if result == "Failed":
return "Some error message"
If your calling function handles the return message and passes it to your Notification Module does that suffice? Or you could use a background task and like @jshaffstall recommends set up a timer to poll it.