From a921aef6c47cecbacef5173f03c07c52e6bc8fea Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 4 May 2010 11:41:54 +0200 Subject: [PATCH] Fixed late binding of url_prefix. This fixes #29. --- flask.py | 2 +- tests/flask_tests.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/flask.py b/flask.py index 268dec38..1d0fa852 100644 --- a/flask.py +++ b/flask.py @@ -448,7 +448,7 @@ class Module(_PackageBoundObject): """ def register_rule(state): the_rule = rule - if self.url_prefix: + if state.url_prefix: the_rule = state.url_prefix + rule state.app.add_url_rule(the_rule, '%s.%s' % (self.name, endpoint), view_func, **options) diff --git a/tests/flask_tests.py b/tests/flask_tests.py index d57370f8..8b3f7640 100644 --- a/tests/flask_tests.py +++ b/tests/flask_tests.py @@ -441,6 +441,15 @@ class ModuleTestCase(unittest.TestCase): assert catched == ['before-app', 'before-admin', 'after-admin', 'after-app'] + def test_late_binding(self): + app = flask.Flask(__name__) + admin = flask.Module(__name__, 'admin') + @admin.route('/') + def index(): + return '42' + app.register_module(admin, url_prefix='/admin') + assert app.test_client().get('/admin/').data == '42' + def suite(): from minitwit_tests import MiniTwitTestCase