diff --git a/CHANGELOG.md b/CHANGELOG.md index afc2e17244..2282b083e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.26.5 - 2018-09-10 +## Fixed +- Fix `get_asset_url` with a different `assets_url_path`. [#374](https://github.com/plotly/dash/pull/374) + ## 0.26.4 - 2018-08-28 ## Fixed - Set `url_base_pathname` to `None` in `Dash.__init__`. Fix [#364](https://github.com/plotly/dash/issues/364) diff --git a/dash/_utils.py b/dash/_utils.py index 9b1a48faae..17dc247ebe 100644 --- a/dash/_utils.py +++ b/dash/_utils.py @@ -20,14 +20,19 @@ def format_tag(tag_name, attributes, inner='', closed=False, opened=False): '{}="{}"'.format(k, v) for k, v in attributes.items()])) -def get_asset_path(requests_pathname, routes_pathname, asset_path): +def get_asset_path( + requests_pathname, + routes_pathname, + asset_path, + asset_url_path): + i = requests_pathname.rfind(routes_pathname) req = requests_pathname[:i] return '/'.join([ # Only take the first part of the pathname req, - 'assets', + asset_url_path, asset_path ]) diff --git a/dash/dash.py b/dash/dash.py index a8414203cc..28e2dfb912 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -101,6 +101,7 @@ def __init__( self._assets_folder = assets_folder or os.path.join( flask.helpers.get_root_path(name), 'assets' ) + self._assets_url_path = assets_url_path # allow users to supply their own flask server self.server = server or Flask(name, static_folder=static_folder) @@ -944,10 +945,14 @@ def add_resource(p, filepath): self._favicon = path def get_asset_url(self, path): - return _get_asset_path( + asset = _get_asset_path( self.config.requests_pathname_prefix, self.config.routes_pathname_prefix, - path) + path, + self._assets_url_path.lstrip('/') + ) + + return asset def run_server(self, port=8050, diff --git a/dash/version.py b/dash/version.py index cddea31832..241959b0dd 100644 --- a/dash/version.py +++ b/dash/version.py @@ -1 +1 @@ -__version__ = '0.26.4' +__version__ = '0.26.5' diff --git a/tests/test_configs.py b/tests/test_configs.py index 6b65613a90..71dac668ba 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -92,16 +92,16 @@ def test_pathname_prefix_environ_requests(self): def test_pathname_prefix_assets(self): req = '/' routes = '/' - path = get_asset_path(req, routes, 'reset.css') + path = get_asset_path(req, routes, 'reset.css', 'assets') self.assertEqual('/assets/reset.css', path) req = '/requests/' - path = get_asset_path(req, routes, 'reset.css') + path = get_asset_path(req, routes, 'reset.css', 'assets') self.assertEqual('/requests/assets/reset.css', path) req = '/requests/routes/' routes = '/routes/' - path = get_asset_path(req, routes, 'reset.css') + path = get_asset_path(req, routes, 'reset.css', 'assets') self.assertEqual('/requests/assets/reset.css', path) diff --git a/tests/test_integration.py b/tests/test_integration.py index 1c42bce431..3fcce93c52 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -363,7 +363,9 @@ def test_index_customization(self): self.percy_snapshot('custom-index') def test_assets(self): - app = dash.Dash(assets_folder='tests/assets', + app = dash.Dash(__name__, + assets_folder='tests/assets', + assets_url_path='/test-assets', assets_ignore='.*ignored.*') app.index_string = '''