MCPcopy Index your code
hub / github.com/plotly/dash / get_relative_path

Method get_relative_path

dash/dash.py:1830–1869  ·  view source on GitHub ↗

Return a path with `requests_pathname_prefix` prefixed before it. Use this function when specifying local URL paths that will work in environments regardless of what `requests_pathname_prefix` is. In some deployment environments, like Dash Enterprise, `reques

(self, path)

Source from the content-addressed store, hash-verified

1828 return _get_paths.app_get_asset_url(self.config, path)
1829
1830 def get_relative_path(self, path):
1831 """
1832 Return a path with `requests_pathname_prefix` prefixed before it.
1833 Use this function when specifying local URL paths that will work
1834 in environments regardless of what `requests_pathname_prefix` is.
1835 In some deployment environments, like Dash Enterprise,
1836 `requests_pathname_prefix` is set to the application name,
1837 e.g. `my-dash-app`.
1838 When working locally, `requests_pathname_prefix` might be unset and
1839 so a relative URL like `/page-2` can just be `/page-2`.
1840 However, when the app is deployed to a URL like `/my-dash-app`, then
1841 `app.get_relative_path('/page-2')` will return `/my-dash-app/page-2`.
1842 This can be used as an alternative to `get_asset_url` as well with
1843 `app.get_relative_path('/assets/logo.png')`
1844
1845 Use this function with `app.strip_relative_path` in callbacks that
1846 deal with `dcc.Location` `pathname` routing.
1847 That is, your usage may look like:
1848 ```
1849 app.layout = html.Div([
1850 dcc.Location(id='url'),
1851 html.Div(id='content')
1852 ])
1853 @app.callback(Output('content', 'children'), [Input('url', 'pathname')])
1854 def display_content(path):
1855 page_name = app.strip_relative_path(path)
1856 if not page_name: # None or ''
1857 return html.Div([
1858 dcc.Link(href=app.get_relative_path('/page-1')),
1859 dcc.Link(href=app.get_relative_path('/page-2')),
1860 ])
1861 elif page_name == 'page-1':
1862 return chapters.page_1
1863 if page_name == "page-2":
1864 return chapters.page_2
1865 ```
1866 """
1867 return _get_paths.app_get_relative_path(
1868 self.config.requests_pathname_prefix, path
1869 )
1870
1871 def strip_relative_path(self, path: str) -> Union[str, None]:
1872 """

Callers 5

test_get_relative_pathFunction · 0.95
_set_redirectFunction · 0.80
add_redirect_ruleMethod · 0.80
add_redirect_ruleMethod · 0.80
add_redirect_ruleMethod · 0.80

Calls

no outgoing calls

Tested by 1

test_get_relative_pathFunction · 0.76