Python decorators possible with Anvil?

I’m looking to implement a simple Python decorator in anvil. I’ve attached the project I’m working with. The decorator is f1, and resides in the “Homepage” form. Not sure what I’m doing wrong here…

I’ve decorated a simple “greet” function with f1.

Here’s the app:
https://anvil.works/build#clone:N5U5K34KSFW5EEGH=Z2QKVAEZNRVQHFXHVAUOF22K

A side note: I’m trying to figure out how this works so I can decorate textboxes and other various inputs with validation decorators to save time doing simple validation.

1 Like

The use of self is the problem…

I think to make your function work you need to call @self.f1 since you’ve defined the wrapper from within the class Form.

You could also define your wrapping function outside of the class and do away with the self altogether.

4 Likes

“The use of self is the problem” sounds like some sort of proverb :wink:

I moved the function outside of the class and did away with self. I have now reached true enlightenment.

4 Likes