Using Pages inside Python Classes #540
-
How do you go about creating a page function inside of a python class? When I attempt to make a page like this: class HomePage:
def __init__(self):
#some content here
@ui.page('/')
def index_page(self) -> None:
#some content here I get an error of value_error.missing - which looks like it gets confused by the self keyword being added Is it possible to include a page function in a class like this or should it be done some other way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Interesting. I've never thought about that. But it's a really good question. FastAPI seems also unable to do this: class Test:
@app.get('/test')
def test(self):
return 'does this work?' Returns a json stating "value self is missing" instead of "does this work?". But it does not mean that NiceGUI should fail here too. Are there any good reasons why this would be a bad idea? |
Beta Was this translation helpful? Give feedback.
Interesting. I've never thought about that. But it's a really good question. FastAPI seems also unable to do this:
Returns a json stating "value self is missing" instead of "does this work?". But it does not mean that NiceGUI should fail here too. Are there any good reasons why this would be a bad idea?