Skip to content

Commit 4d580da

Browse files
committed
add docs for get_asset_url
1 parent 9566578 commit 4d580da

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

dash/_get_paths.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55

66

77
def get_asset_url(path):
8+
"""
9+
Return the URL for the provided `path` in the assets directory.
10+
11+
`dash.get_asset_url` is not compatible with Dash Snapshots.
12+
Use `get_asset_url` on the app instance instead: `app.get_asset_url`.
13+
See `app.get_asset_url` for more information.
14+
"""
815
return app_get_asset_url(CONFIG, path)
916

1017

dash/dash.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,35 @@ def _hash(script):
15471547
]
15481548

15491549
def get_asset_url(self, path):
1550+
"""
1551+
Return the URL for the provided `path` in the assets directory.
1552+
1553+
If `assets_external_path` is set, `get_asset_url` returns
1554+
`assets_external_path` + `assets_url_path` + `path`, where
1555+
`path` is the path passed to `get_asset_url`.
1556+
1557+
Otherwise, `get_asset_url` returns
1558+
`requests_pathname_prefix` + `assets_url_path` + `path`, where
1559+
`path` is the path passed to `get_asset_url`.
1560+
1561+
Use `get_asset_url` in an app to access assets at the correct location
1562+
in different environments. `requests_pathname_prefix` in a deployed app
1563+
on Dash Enterprise includes the app name.
1564+
1565+
For an app on Dash Enterprise called "my-app",
1566+
`app.get_asset_url("image.png")` would return:
1567+
1568+
```
1569+
/my-app/assets/image.png
1570+
```
1571+
1572+
While the same app running locally,
1573+
without `requests_pathname_prefix` set would return:
1574+
1575+
```
1576+
/assets/image.png
1577+
```
1578+
"""
15501579
return _get_paths.app_get_asset_url(self.config, path)
15511580

15521581
def get_relative_path(self, path):

0 commit comments

Comments
 (0)