mirror of https://github.com/pallets/flask.git
				
				
				
			Merge pull request #876 from defuz/templates-auto-reload
Add TEMPLATES_AUTO_RELOAD config key
This commit is contained in:
		
						commit
						7f5b6c692d
					
				
							
								
								
									
										4
									
								
								CHANGES
								
								
								
								
							
							
						
						
									
										4
									
								
								CHANGES
								
								
								
								
							|  | @ -21,6 +21,10 @@ Version 1.0 | ||||||
| - Added :attr:`flask.Flask.config_class`. | - Added :attr:`flask.Flask.config_class`. | ||||||
| - Added :meth:`flask.config.Config.get_namespace`. | - Added :meth:`flask.config.Config.get_namespace`. | ||||||
| 
 | 
 | ||||||
|  | - Added ``TEMPLATES_AUTO_RELOAD`` config key. If disabled the  | ||||||
|  |   templates will be reloaded only if the application is running in  | ||||||
|  |   debug mode. For higher performance it’s possible to disable that. | ||||||
|  | 
 | ||||||
| Version 0.10.2 | Version 0.10.2 | ||||||
| -------------- | -------------- | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -174,6 +174,12 @@ The following configuration values are used internally by Flask: | ||||||
|                                   if they are not requested by an |                                   if they are not requested by an | ||||||
|                                   XMLHttpRequest object (controlled by |                                   XMLHttpRequest object (controlled by | ||||||
|                                   the ``X-Requested-With`` header) |                                   the ``X-Requested-With`` header) | ||||||
|  | ``TEMPLATES_AUTO_RELOAD``         Flask checks if template was modified each | ||||||
|  |                                   time it is requested and reloads it if | ||||||
|  |                                   necessary. But disk I/O is costly and it may | ||||||
|  |                                   be viable to disable this feature by setting | ||||||
|  |                                   this key to ``False``. This option does not | ||||||
|  |                                   affect debug mode. | ||||||
| ================================= ========================================= | ================================= ========================================= | ||||||
| 
 | 
 | ||||||
| .. admonition:: More on ``SERVER_NAME`` | .. admonition:: More on ``SERVER_NAME`` | ||||||
|  | @ -222,6 +228,9 @@ The following configuration values are used internally by Flask: | ||||||
| .. versionadded:: 1.0 | .. versionadded:: 1.0 | ||||||
|    ``SESSION_REFRESH_EACH_REQUEST`` |    ``SESSION_REFRESH_EACH_REQUEST`` | ||||||
| 
 | 
 | ||||||
|  | .. versionadded:: 1.0 | ||||||
|  |    ``TEMPLATES_AUTO_RELOAD`` | ||||||
|  | 
 | ||||||
| Configuring from Files | Configuring from Files | ||||||
| ---------------------- | ---------------------- | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -305,6 +305,7 @@ class Flask(_PackageBoundObject): | ||||||
|         'JSON_AS_ASCII':                        True, |         'JSON_AS_ASCII':                        True, | ||||||
|         'JSON_SORT_KEYS':                       True, |         'JSON_SORT_KEYS':                       True, | ||||||
|         'JSONIFY_PRETTYPRINT_REGULAR':          True, |         'JSONIFY_PRETTYPRINT_REGULAR':          True, | ||||||
|  |         'TEMPLATES_AUTO_RELOAD':                True, | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|     #: The rule object to use for URL rules created.  This is used by |     #: The rule object to use for URL rules created.  This is used by | ||||||
|  | @ -655,10 +656,16 @@ class Flask(_PackageBoundObject): | ||||||
|         this function to customize the behavior. |         this function to customize the behavior. | ||||||
| 
 | 
 | ||||||
|         .. versionadded:: 0.5 |         .. versionadded:: 0.5 | ||||||
|  |         .. versionchanged:: 1.0 | ||||||
|  |            ``Environment.auto_reload`` set in accordance with | ||||||
|  |            ``TEMPLATES_AUTO_RELOAD`` configuration option. | ||||||
|         """ |         """ | ||||||
|         options = dict(self.jinja_options) |         options = dict(self.jinja_options) | ||||||
|         if 'autoescape' not in options: |         if 'autoescape' not in options: | ||||||
|             options['autoescape'] = self.select_jinja_autoescape |             options['autoescape'] = self.select_jinja_autoescape | ||||||
|  |         if 'auto_reload' not in options: | ||||||
|  |             options['auto_reload'] = self.debug \ | ||||||
|  |                 or self.config['TEMPLATES_AUTO_RELOAD'] | ||||||
|         rv = Environment(self, **options) |         rv = Environment(self, **options) | ||||||
|         rv.globals.update( |         rv.globals.update( | ||||||
|             url_for=url_for, |             url_for=url_for, | ||||||
|  |  | ||||||
|  | @ -295,6 +295,14 @@ class TemplatingTestCase(FlaskTestCase): | ||||||
|         rv = app.test_client().get('/') |         rv = app.test_client().get('/') | ||||||
|         self.assert_equal(rv.data, b'<h1>Jameson</h1>') |         self.assert_equal(rv.data, b'<h1>Jameson</h1>') | ||||||
| 
 | 
 | ||||||
|  |     def test_templates_auto_reload(self): | ||||||
|  |         app = flask.Flask(__name__) | ||||||
|  |         self.assert_true(app.config['TEMPLATES_AUTO_RELOAD']) | ||||||
|  |         self.assert_true(app.jinja_env.auto_reload) | ||||||
|  |         app = flask.Flask(__name__) | ||||||
|  |         app.config['TEMPLATES_AUTO_RELOAD'] = False | ||||||
|  |         self.assert_false(app.jinja_env.auto_reload) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| def suite(): | def suite(): | ||||||
|     suite = unittest.TestSuite() |     suite = unittest.TestSuite() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue