diff --git a/flask_s3.py b/flask_s3.py index 6298cda..c03cbc7 100644 --- a/flask_s3.py +++ b/flask_s3.py @@ -26,7 +26,10 @@ def url_for(endpoint, **values): app = current_app if 'S3_BUCKET_NAME' not in app.config: raise ValueError("S3_BUCKET_NAME not found in app configuration.") - + + if app.debug and not app.config['USE_S3_DEBUG']: + return flask_url_for(endpoint, **values) + if endpoint == 'static' or endpoint.endswith('.static'): scheme = 'http' if app.config['S3_USE_HTTPS']: @@ -189,6 +192,5 @@ class FlaskS3(object): app.config.setdefault(k, v) if app.config['USE_S3']: - if not app.debug or app.config['USE_S3_DEBUG']: - app.jinja_env.globals['url_for'] = url_for + app.jinja_env.globals['url_for'] = url_for diff --git a/tests/test_flask_static.py b/tests/test_flask_static.py index 34ba24b..12135ac 100644 --- a/tests/test_flask_static.py +++ b/tests/test_flask_static.py @@ -84,6 +84,17 @@ class UrlTests(unittest.TestCase): exp = 'https://foo.s3.amazonaws.com/static/bah.js' self.assertEquals(self.client_get(ufs).data, exp) + def test_url_for_debug(self): + """Tests Flask-S3 behaviour in debug mode.""" + self.app.debug = True + # static endpoint url_for in template + ufs = "{{url_for('static', filename='bah.js')}}" + exp = '/static/bah.js' + self.assertEquals(self.client_get(ufs).data, exp) + self.app.config['USE_S3_DEBUG'] = True + exp = 'https://foo.s3.amazonaws.com/static/bah.js' + self.assertEquals(self.client_get(ufs).data, exp) + def test_url_for_blueprint(self): """Tests that correct url formed for static asset in blueprint.""" # static endpoint url_for in template