AuthorizedPage class
Bases: _Renderer
A page that shows a different content depending on RoleTraits
.
Taipy can display different page contents depending on who the user using the application is. You may want to hide some controls for users that are not allowed to perform specific tasks or even change the entire page content altogether.
To achieve this page content selection, you must create a RoleTraits
filter that,
when applied the authenticated user roles, will select the appropriate page content
that gets displayed.
Attributes:
Name | Type | Description |
---|---|---|
traits |
RoleTraits
|
The role traits filter that is used to select the displayed content. |
Show a different page depending on the user's credentials
The following code creates two different pages: admin_home_page and home_page.
When the "home" page is requested, the admin_home_page page will be presented to the
user if and only if the user was authenticated successfully
(using login
). Otherwise, the displayed page is home_page.
Only authenticated users with the "admin" role will see the content of admin_home_page.
from taipy.gui import Gui, Markdown
from taipy.enterprise.gui import AuthorizedPage
admin_home_page = Markdown("# Administration Home page")
home_page = Markdown("# Home page")
gui.add_page("home", AuthorizedPage(AnyOf("admin", admin_home_page, home_page)))
Methods¶
__init__() ¶
__init__(traits: RoleTraits) -> None
Initialize a new AuthorizedPage instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
RoleTraits
|
The role traits filter that is used to select the displayed content. |
required |
create_page() ¶
create_page() -> t.Optional[Page]
Create the page content for page modules.
If this page is a page module, this method must be overloaded and return the page content.
This method should never be called directly: only the Taipy GUI internals will.
The default implementation returns None, indicating that this class does not implement a page module.
Returns:
Type | Description |
---|---|
Optional[Page]
|
The page content for this Page subclass, making it a page module. |
set_style() ¶
set_style(style: Dict[str, Dict[str, Any]]) -> Page
Set the style for this page.
The style parameter must contain a series of CSS rules that apply to the generated
page.
Each key of this dictionary should be a CSS selector and its associated value must be
a CSS declaration or a CSS rule itself, benefiting from
nested CSS
features.
For example, you could set the style parameter to:
{
"class1": {
"css_property1": "css_value1",
}
"class2": {
"class3": {
"css_property2": "css_value2",
}
}
}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
dict
|
A dictionary describing the style as CSS or Nested CSS. |
required |
Returns:
Type | Description |
---|---|
Page
|
This |