✨ Announcing our seed funding led by Lux Capital! Read more about it on our blog
DocsBlogChangelog

Search documentation...

/

Star

12k+

[ Learn ]

[ Concepts ]

[ Reference ]

State utility methods


The State object has several methods that return information about the current page, user and session.
Some examples:
  • get_client_ip(): Returns the IP of current user.

  • get_current_page(): Returns the URL the current page.

  • get_cookies(): Returns the current user's browser cookies.

class State(rx.State):
    @rx.var
    def client_ip(self):
        return self.get_client_ip()

    @rx.var
    def current_page(self):
        return self.get_current_page()

    @rx.var
    def cookies(self):
        return str(self.get_cookies())


def index():
    return rx.vstack(
        rx.text(State.client_ip),
        rx.text(State.current_page),
        rx.text(State.cookies),
    )


app = rx.App()
app.add_page(index)
Check out the State class definition to see all available methods.
← SubstatesStyling Overview →

Copyright © 2023 Pynecone, Inc.