Skip to content

Commit bea2697

Browse files
committed
Adds kwargs to Dash.init_app()
1 parent b3bb96d commit bea2697

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

dash/dash.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,11 @@ def __init__(
356356
"assets_folder",
357357
"assets_url_path",
358358
"eager_loading",
359-
"url_base_pathname",
360-
"routes_pathname_prefix",
361-
"requests_pathname_prefix",
362359
"serve_locally",
363360
"compress",
364361
],
365362
"Read-only: can only be set in the Dash constructor",
366363
)
367-
self.config.finalize(
368-
"Invalid config key. Some settings are only available "
369-
"via the Dash constructor"
370-
)
371364

372365
# keep title as a class property for backwards compatibility
373366
self.title = title
@@ -427,8 +420,23 @@ def __init__(
427420

428421
self.logger.setLevel(logging.INFO)
429422

430-
def init_app(self, app=None):
423+
def init_app(self, app=None, **kwargs):
431424
"""Initialize the parts of Dash that require a flask app."""
425+
426+
self.config.update(kwargs)
427+
self.config.set_read_only(
428+
[
429+
"url_base_pathname",
430+
"routes_pathname_prefix",
431+
"requests_pathname_prefix",
432+
],
433+
"Read-only: can only be set in the Dash constructor or during init_app()",
434+
)
435+
436+
self.config.finalize(
437+
"Invalid config key. Some settings are only available "
438+
"via the Dash constructor"
439+
)
432440
config = self.config
433441

434442
if app is not None:
@@ -438,6 +446,7 @@ def init_app(self, app=None):
438446
config.routes_pathname_prefix.replace("/", "_"), "dash_assets"
439447
)
440448

449+
print(assets_blueprint_name)
441450
self.server.register_blueprint(
442451
flask.Blueprint(
443452
assets_blueprint_name,

tests/unit/test_configs.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,19 @@ def test_title():
370370
assert "<title>Hello World</title>" in app.index()
371371
app = Dash(title="Custom Title")
372372
assert "<title>Custom Title</title>" in app.index()
373+
374+
375+
def test_app_delayed_config():
376+
app = Dash(server=False)
377+
app.init_app(app=Flask("test"), requests_pathname_prefix="/dash/")
378+
379+
assert app.config.requests_pathname_prefix == "/dash/"
380+
381+
with pytest.raises(AttributeError):
382+
app.config.name = "cannot update me"
383+
384+
385+
def test_app_invalid_delayed_config():
386+
app = Dash(server=False)
387+
with pytest.raises(AttributeError):
388+
app.init_app(app=Flask("test"), name="too late 2 update")

0 commit comments

Comments
 (0)