Skip to content

@ui.page('/sub_path') decorator shows page at "/" rather than at "/sub_path" #3981

Closed Answered by falkoschindler
belalhmedan90 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @belalhmedan90,

Let's break it down:

class MyClass:
    def __init__(self):
        self.create_page()

    @ui.page('/sub_path')
    def create_page(self):
        ui.label("Here")

MyClass()

Now two things happen:

  • With the ui.page decorator you define a new route at "/sub_path" which will call the create_page method. Note that this function has a parameter self. So when accessing the route "/sub_path?self=something", the method is called and you see "Here".
  • On startup you're instantiating MyClass(), which calls create_page() and creates a label in the current context, which is the auto-index page. So when accessing the route "/", you also see "Here".

To fix this, you can nest the p…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@belalhmedan90
Comment options

@falkoschindler
Comment options

Answer selected by belalhmedan90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants