Skip to content

Commit 71fb742

Browse files
authored
Merge pull request #377 from hinnefe2/unnest-init-add-url-function
Move add_url function definition out of Dash.__init__()
2 parents 99867f5 + 72cc1f2 commit 71fb742

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.28.2 - 2018-10-05
2+
## Added
3+
- Moved `add_url` function definition out of `Dash.__init__` [#377](https://github.com/plotly/dash/pull/377)
4+
15
## 0.28.1 - 2018-09-26
26
## Fixed
37
- Missing favicon package_data from setup.py [#407](https://github.com/plotly/dash/pull/407)

dash/dash.py

+23-19
Original file line numberDiff line numberDiff line change
@@ -170,58 +170,51 @@ def _handle_error(error):
170170
self.registered_paths = {}
171171

172172
# urls
173+
self.routes = []
173174

174-
def add_url(name, view_func, methods=('GET',)):
175-
self.server.add_url_rule(
176-
name,
177-
view_func=view_func,
178-
endpoint=name,
179-
methods=list(methods)
180-
)
181-
182-
add_url(
175+
self._add_url(
183176
'{}_dash-layout'.format(self.config['routes_pathname_prefix']),
184177
self.serve_layout)
185178

186-
add_url(
179+
self._add_url(
187180
'{}_dash-dependencies'.format(
188181
self.config['routes_pathname_prefix']),
189182
self.dependencies)
190183

191-
add_url(
184+
self._add_url(
192185
'{}_dash-update-component'.format(
193186
self.config['routes_pathname_prefix']),
194187
self.dispatch,
195188
['POST'])
196189

197-
add_url((
190+
self._add_url((
198191
'{}_dash-component-suites'
199192
'/<string:package_name>'
200193
'/<path:path_in_package_dist>').format(
201194
self.config['routes_pathname_prefix']),
202-
self.serve_component_suites)
195+
self.serve_component_suites)
203196

204-
add_url(
197+
self._add_url(
205198
'{}_dash-routes'.format(self.config['routes_pathname_prefix']),
206199
self.serve_routes)
207200

208-
add_url(
201+
self._add_url(
209202
self.config['routes_pathname_prefix'],
210203
self.index)
211204

212205
# catch-all for front-end routes, used by dcc.Location
213-
add_url(
206+
self._add_url(
214207
'{}<path:path>'.format(self.config['routes_pathname_prefix']),
215208
self.index)
216209

217-
add_url('{}_favicon.ico'.format(self.config['routes_pathname_prefix']),
218-
self._serve_default_favicon)
210+
self._add_url(
211+
'{}_favicon.ico'.format(self.config['routes_pathname_prefix']),
212+
self._serve_default_favicon)
219213

220214
self.server.before_first_request(self._setup_server)
221215

222216
self._layout = None
223217
self._cached_layout = None
224-
self.routes = []
225218
self._dev_tools = _AttributeDict({
226219
'serve_dev_bundles': False
227220
})
@@ -230,6 +223,17 @@ def add_url(name, view_func, methods=('GET',)):
230223
self.server.errorhandler(exceptions.InvalidResourceError)(
231224
self._invalid_resources_handler)
232225

226+
def _add_url(self, name, view_func, methods=('GET',)):
227+
self.server.add_url_rule(
228+
name,
229+
view_func=view_func,
230+
endpoint=name,
231+
methods=list(methods))
232+
233+
# record the url in Dash.routes so that it can be accessed later
234+
# e.g. for adding authentication with flask_login
235+
self.routes.append(name)
236+
233237
@property
234238
def layout(self):
235239
return self._layout

dash/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.28.1'
1+
__version__ = '0.28.2'

0 commit comments

Comments
 (0)