Skip to content

Commit

Permalink
Better explain the base_url Gui setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienLelaquais committed Dec 20, 2024
1 parent 3f38914 commit 008435d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 20 deletions.
32 changes: 31 additions & 1 deletion docs/userman/advanced_features/configuration/gui-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,37 @@ Here is the list of the configuration parameters you can use in
`Gui.run()^` or `Gui.get_flask_app()^` so it is served by the target web server.
- <a name="p-base_url"></a>*base_url* (str or None, default: "/"): a string used as a prefix to
the path part of the exposed URL, so one can deploy a Taipy GUI application in a path
different from the root of the web site.
different from the root of the web site.<br/>
If you need to expose the application under the prefix "*my_application*", you can set this
path to the *base_url* paramameter of the `Gui.run()^` method:
```python
Gui(pages=...).run(base_url="/my_application")
```
The application prefix must also be handled at the web server level, to properly proxy the
requests.<br/>
Here is an example using [**ngnix**](https://nginx.org/): the server is listening to port 8080
and redirecting the traffic to the Taipy application, locally on port 5000. Here is what could
be indicated in the web server configuration file:
```
server {
listen 8080;

location /my_application {
rewrite /my_application/(.*) /$1 break;
rewrite /my_application / break;
proxy_pass http://172.17.0.1:5000;
}

location /my_application/socket.io {
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://172.17.0.1:5000/socket.io;
}
}
```
Note that web socket redirection needs to be setup.
- <a name="p-allow_unsafe_werkzeug"></a>*allow_unsafe_werkzeug* (bool, default: False): hides
some [Flask-SocketIO](https://pypi.org/project/Flask-SocketIO/) runtime errors in some
debugging scenarios. This is set to True when [*debug*](#p-debug) is set to True.
Expand Down
59 changes: 40 additions & 19 deletions docs/userman/gui/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,50 +211,71 @@ associates a page with its name:
# gui.run()
```

You could have also used the `(Gui.)add_page()` function.
You could have also used the `(Gui.)add_page()^` function for each page.


In this situation, to see the pages in your browser, the address you will use
will be *localhost:5000/home* or *localhost:5000/about*. Learn how to natigate between pages [here](../pages/navigate/index.md).
In this situation, to see the pages in your browser, the address you will use will be
*localhost:5000/home* or *localhost:5000/about*. Learn how to navigate between pages
[here](../pages/navigate/index.md).<br/>
If you point the browser to the root of the server (*localhost:5000/*) then it will be redirected to
the first added page. In our situation, the *home* page at *localhost:5000/home*.

Note that if pages are created in different modules, the variables that they can bind
to visual elements may have a scope limited to their origin module. See
[Page scopes](../binding.md#scope-for-variable-binding) for more details.

## Root page

The *Root* page is the page located at `"/"` (or the value of the
[*base_url*](../../advanced_features/configuration/gui-config.md#p-base_url) configuration setting).
The content of the page will be shown at the top of every page of your application.
The *Root* page is the page located at `"/"`.

You may choose to expose you application pages to another top directory. To do this, you must
prefix each page name with the directory you wish to expose:
```python
pages = {
"/": root_md,
"my_application/home": home_md,
"my_application/about": about_md
}
```

When opening a browser on the page located at *localhost:5000/*, it will be redirected to the
first declared page, at *localhost:5000/my_application/home*.

The content of the root page will be displayed at the top of every page of your application.

If you want to expose your application at a given root directory in a production environment, you
may want to set the value of the
[*base_url*](../../advanced_features/configuration/gui-config.md#p-base_url) configuration setting.
Please refer to the documentation for this setting for more information.

## Application header and footer

Your application may also need to hold a footer on all the pages it uses.<br/>
You can use the pseudo-control `<|content|>` to achieve the expected result: this
You can use the pseudo-control `content` to achieve the expected result: this
visual element is not *really* a control: It is a placeholder for page content, used in the
root page of your application, and is replaced by the target page content when the application
runs.

!!! example
!!! example "Adding a page footer"
```python
from taipy import Gui

if __name__ == "__main__":
root_md="""
root_md="""
# Multi-page application

<|content|>

This application was created with [Taipy](https://www.taipy.io/).
"""
home_md="## Home"
about_md="## About"
"""
home_md="## Home"
about_md="## About"

pages = {
"/": root_md,
"home": home_md,
"about": about_md
}
pages = {
"/": root_md,
"home": home_md,
"about": about_md
}

if __name__ == "__main__":
Gui(pages=pages).run()
```

Expand Down

0 comments on commit 008435d

Please sign in to comment.