diff --git a/CHANGELOG.md b/CHANGELOG.md index fd476b786f..262ab29931 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## [UNRELEASED] - 2019-01-23 +## Fixed +- Asset blueprint takes routes prefix into it's static path. [#547](https://github.com/plotly/dash/pull/547) +- Asset url path no longer strip routes from requests. [#547](https://github.com/plotly/dash/pull/547) + +## Changed +- `assets_folder` argument now default to 'assets' [#547](https://github.com/plotly/dash/pull/547) +- The assets folder is now always relative to the given root path of `name` argument, the default of `__main__` will get the `cwd`. [#547](https://github.com/plotly/dash/pull/547) +- No longer coerce the name argument from the server if the server argument is provided. [#547](https://github.com/plotly/dash/pull/547) + ## [0.35.2] - 2019-01-11 ## Fixed - Fix typo in some exception names [#522](https://github.com/plotly/dash/pull/522) diff --git a/dash/_utils.py b/dash/_utils.py index 811da08ebe..0e909b31ae 100644 --- a/dash/_utils.py +++ b/dash/_utils.py @@ -29,15 +29,12 @@ def generate_hash(): 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, + requests_pathname.rstrip('/'), asset_url_path, asset_path ]) diff --git a/dash/dash.py b/dash/dash.py index 21f5e710b7..5eb07ae197 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -76,7 +76,7 @@ def __init__( name='__main__', server=None, static_folder='static', - assets_folder=None, + assets_folder='assets', assets_url_path='/assets', assets_ignore='', include_assets_files=True, @@ -102,21 +102,15 @@ def __init__( See https://github.com/plotly/dash/issues/141 for details. ''', DeprecationWarning) - name = name if server is None else server.name - self._assets_folder = assets_folder or os.path.join( - flask.helpers.get_root_path(name), 'assets' + self._assets_folder = os.path.join( + flask.helpers.get_root_path(name), + assets_folder, ) 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) - if 'assets' not in self.server.blueprints: - self.server.register_blueprint( - flask.Blueprint('assets', 'assets', - static_folder=self._assets_folder, - static_url_path=assets_url_path)) - env_configs = _configs.env_configs() url_base_pathname, routes_pathname_prefix, requests_pathname_prefix = \ @@ -146,6 +140,22 @@ def __init__( env_configs, 2678400)) }) + assets_blueprint_name = '{}{}'.format( + self.config.routes_pathname_prefix.replace('/', '_'), + 'dash_assets' + ) + + self.server.register_blueprint( + flask.Blueprint( + assets_blueprint_name, name, + static_folder=self._assets_folder, + static_url_path='{}{}'.format( + self.config.routes_pathname_prefix, + assets_url_path.lstrip('/') + ) + ) + ) + # list of dependencies self.callback_map = {} @@ -1056,7 +1066,6 @@ def _serve_default_favicon(self): def get_asset_url(self, path): asset = _get_asset_path( self.config.requests_pathname_prefix, - self.config.routes_pathname_prefix, path, self._assets_url_path.lstrip('/') ) diff --git a/tests/test_configs.py b/tests/test_configs.py index 3a43bef9b3..ef630e6cdb 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -91,18 +91,16 @@ def test_pathname_prefix_environ_requests(self): def test_pathname_prefix_assets(self): req = '/' - routes = '/' - path = get_asset_path(req, routes, 'reset.css', 'assets') + path = get_asset_path(req, 'reset.css', 'assets') self.assertEqual('/assets/reset.css', path) req = '/requests/' - path = get_asset_path(req, routes, 'reset.css', 'assets') + path = get_asset_path(req, 'reset.css', 'assets') self.assertEqual('/requests/assets/reset.css', path) req = '/requests/routes/' - routes = '/routes/' - path = get_asset_path(req, routes, 'reset.css', 'assets') - self.assertEqual('/requests/assets/reset.css', path) + path = get_asset_path(req, 'reset.css', 'assets') + self.assertEqual('/requests/routes/assets/reset.css', path) if __name__ == '__main__': diff --git a/tests/test_integration.py b/tests/test_integration.py index 2d9be799c4..e5be2a4298 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -361,7 +361,6 @@ def test_index_customization(self): def test_assets(self): app = dash.Dash(__name__, - assets_folder='tests/assets', assets_ignore='.*ignored.*') app.index_string = '''