Skip to content
Myr

clean up FLASK_ENV docs [ci skip]

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent 2949306 · Browse files · 7 files+129 added−83 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+129 added−83 removed

  • other:+129 added−83 removed

7 files+129 added−83 removed

modified:docs/tutorial/packaging.rst+2 added-2 removed
80 unmodified lines
81 export FLASK_ENV=development82 flask run8384(In case you are on Windows you need to use ``set`` instead of ``export``).85The :envvar:`FLASK_ENV` flag if set to ``development`` turns on all86development features such as enabling the interactive debugger.85Exporting ``FLASK_ENV=development`` turns on all development features86such as enabling the interactive debugger.8788*Never leave debug mode activated in a production system*, because it will89allow users to execute code on the server!90
18 unmodified lines
modified:docs/cli.rst+20 added-15 removed
114 unmodified lines
115 >>>116117Use :meth:`~Flask.shell_context_processor` to add other automatic imports.118119120Environments121------------122123.. versionadded:: 1.0124124The environment in which the Flask app should run is set by the125:envvar:`FLASK_ENV` environment variable. If not set it defaults to126``production``. The other default environment which is known is127``development``. If the env is set to ``development`` the debug mode is128for instance automatically enabled.125The environment in which the Flask app runs is set by the126:envvar:`FLASK_ENV` environment variable. If not set it defaults to127``production``. The other recognized environment is ``development``.128Flask and extensions may choose to enable behaviors based on the129environment.130130Debug Mode131----------131If the env is set to ``development``, the ``flask`` command will enable132debug mode and ``flask run`` will enable the interactive debugger and133reloader.134133Set the :envvar:`FLASK_DEBUG` environment variable to override the134application's :attr:`~Flask.debug` flag. The value ``1`` enables it, ``0``135disables it. Forcing the debug flag on also enables the debugger and reloader136when running the development server.137135::136140 $ FLASK_DEBUG=1 flask run137 $ FLASK_ENV=development flask run138 * Serving Flask app "hello"142 * Forcing debug mode on143 * Env production139 * Environment: development140 * Debug mode: on141 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)142 * Restarting with inotify reloader143 * Debugger is active!144 * Debugger PIN: 223-456-919145146147Debug Mode148----------149150Debug mode will be enabled when :envvar:`FLASK_ENV` is ``development``,151as described above. If you want to control debug mode separately, use152:envvar:`FLASK_DEBUG`. The value ``1`` enables it, ``0`` disables it.153154155.. _dotenv:156157Environment Variables From dotenv158---------------------------------
253 unmodified lines
modified:docs/config.rst+57 added-27 removed
18 unmodified lines
19object. This is the place where Flask itself puts certain configuration20values and also where extensions can put their configuration values. But21this is also where you can have your own configuration.222324Configuration Basics25--------------------2627The :attr:`~flask.Flask.config` is actually a subclass of a dictionary and
14 unmodified lines
42 TESTING=True,43 SECRET_KEY=b'_5#y2L"F4Q8z\n\xec]/'44 )454647Environment and Debug Features48------------------------------4948Some values are special in that they can show unexpected behavior when49changed late. In particular that applies to the Flask environment and50debug mode.50The :data:`ENV` and :data:`DEBUG` config values are special because they51may behave inconsistently if changed after the app has begun setting up.52In order to set the environment and debug mode reliably, Flask uses53environment variables.5452If you use the :command:`flask` script to start a local development server53for instance you should tell Flask that you want to work in the54development environment. For safety reasons we default the flask55environment to production mode instead of development. This is done56because development mode can turn on potentially unsafe features such as57the debugger by default.55The environment is used to indicate to Flask, extensions, and other56programs, like Sentry, what context Flask is running in. It is57controlled with the :envvar:`FLASK_ENV` environment variable and58defaults to ``production``.5959To control the environment and such fundamental features Flask provides60the two environment variables :envvar:`FLASK_ENV` and :envvar:`FLASK_DEBUG`.61In versions of Flask older than 1.0 the :envvar:`FLASK_ENV` environment62variable did not exist.60Setting :envvar:`FLASK_ENV` to ``development`` will enable debug mode.61``flask run`` will use the interactive debugger and reloader by default62in debug mode. To control this separately from the environment, use the63:envvar:`FLASK_DEBUG` flag.6464The most common way to switch Flask to development mode is to tell it to65work on the ``development`` environment::65.. versionchanged:: 1.066 Added :envvar:`FLASK_ENV` to control the environment separately67 from debug mode. The development environment enables debug mode.6867$ export FLASK_ENV=development68$ flask run69To switch Flask to the development environment and enable debug mode,70set :envvar:`FLASK_ENV`::7170(On Windows you need to use ``set`` instead of ``export``).72 $ export FLASK_ENV=development73 $ flask run7472While you can attempt to flip the environment and debug flag separately in73the Flask config from the config file this is strongly discouraged as74those flags are often loaded early and changing them late might not apply75to all systems and extensions.75(On Windows, use ``set`` instead of ``export``.)7677Using the environment variables as described above is recommended. While78it is possible to set :data:`ENV` and :data:`DEBUG` in your config or79code, this is strongly discouraged. They can't be read early by the80``flask`` command, and some systems or extensions may have already81configured themselves based on a previous value.828384Builtin Configuration Values85----------------------------8687The following configuration values are used internally by Flask:8889.. py:data:: ENV9091 What environment the app is running in. Flask and extensions may92 enable behaviors based on the environment, such as enabling debug93 mode. The :attr:`~flask.Flask.env` attribute maps to this config94 key. This is set by the :envvar:`FLASK_ENV` environment variable and95 may not behave as expected if set in code.9697 **Do not enable development when deploying in production.**9899 Default: ``'production'``100101 .. versionadded:: 1.0102103.. py:data:: DEBUG10484 Enable debug mode. When using the development server with ``flask run`` or85 ``app.run``, an interactive debugger will be shown for unhanlded86 exceptions, and the server will be reloaded when code changes.105 Whether debug mode is enabled. When using ``flask run`` to start the106 development server, an interactive debugger will be shown for107 unhandled exceptions, and the server will be reloaded when code108 changes. The :attr:`~flask.Flask.debug` attribute maps to this109 config key. This is enabled when :data:`ENV` is ``'development'``110 and is overridden by the ``FLASK_DEBUG`` environment variable. It111 may not behave as expected if set in code.11288 **Do not enable debug mode in production.**113 **Do not enable debug mode when deploying in production.**11490 Default: ``False``115 Default: ``True`` if :data:`ENV` is ``'production'``, or ``False``116 otherwise.117118.. py:data:: TESTING119120 Enable testing mode. Exceptions are propagated rather than handled by the
243 unmodified lines
364365 ``LOGGER_NAME`` and ``LOGGER_HANDLER_POLICY`` were removed. See366 :ref:`logging` for information about configuration.367368 Added :data:`ENV` to reflect the :envvar:`FLASK_ENV` environment369 variable.370371372Configuring from Files373----------------------374375Configuration becomes more useful if you can store it in a separate file,
263 unmodified lines
modified:docs/quickstart.rst+6 added-5 removed
128 unmodified lines
129That is not very nice and Flask can do better. If you enable debug130support the server will reload itself on code changes, and it will also131provide you with a helpful debugger if things go wrong.132133To enable all development features (and to disable the debug mode) you can134export the ``FLASK_ENV`` environment variable and set it to135``development``133To enable all development features (including debug mode) you can export134the ``FLASK_ENV`` environment variable and set it to ``development``135before running the server::136137 $ export FLASK_ENV=development138 $ flask run139141(On Windows you need to use ``set`` instead of ``export`` and on Flask142versions older than 1.0 you need to export ``FLASK_DEBUG=1`` instead).140(On Windows you need to use ``set`` instead of ``export``.)141142This does the following things:1431441. it activates the debugger1452. it activates the automatic reloader1463. it enables the debug mode on the Flask application.147148You can also control debug mode separately from the environment by149exporting ``FLASK_DEBUG=1``.150151There are more parameters that are explained in the :ref:`server` docs.152153.. admonition:: Attention154
696 unmodified lines
modified:docs/server.rst+8 added-6 removed
19 unmodified lines
20 $ export FLASK_APP=my_application21 $ export FLASK_ENV=development22 $ flask run2324This will enable the debugger, the reloader and then start the server on24This enables the development environment, including the interactive25debugger and reloader, and then starts the server on26*http://localhost:5000/*.2728The individual features of the server can be controlled by passing more28arguments to the ``run`` option. For instance the reloader can be29arguments to the ``run`` option. For instance the reloader can be30disabled::3132 $ flask run --no-reload3334.. note::3535 On older Flask version (before 1.0) the :envvar:`FLASK_ENV`36 environment variable is not supported and you need to enable the37 debug mode separately by setting the :envvar:`FLASK_DEBUG` environment38 variable to ``1``.36 Prior to Flask 1.0 the :envvar:`FLASK_ENV` environment variable was37 not supported and you needed to enable debug mode by exporting38 ``FLASK_DEBUG=1``. This can still be used to control debug mode, but39 you should prefer setting the development environment as shown40 above.4142In Code43-------44
18 unmodified lines
modified:flask/app.py+23 added-20 removed
783 unmodified lines
784 for processor in self.shell_context_processors:785 rv.update(processor())786 return rv787788 #: The environment value. This is typically set from outside the789 #: process by setting the `FLASK_ENV` environment variable and can be790 #: used to quickly switch between different environments like791 #: `production` and `development`. If not set this defaults to792 #: `production`.788 #: What environment the app is running in. Flask and extensions may789 #: enable behaviors based on the environment, such as enabling debug790 #: mode. This maps to the :data:`ENV` config key. This is set by the791 #: :envvar:`FLASK_ENV` environment variable and may not behave as792 #: expected if set in code.793 #:794 #: **Do not enable development when deploying in production.**795 #:796 #: Default: ``'production'``797 env = ConfigAttribute('ENV')798799 def _get_debug(self):800 return self.config['DEBUG']801802 def _set_debug(self, value):798 self._set_debug_value(value)803 self.config['DEBUG'] = value804 self.jinja_env.auto_reload = self.templates_auto_reload805800 #: The debug flag. If this is ``True`` it enables debugging of the801 #: application. In debug mode the debugger will kick in when an802 #: unhandled exception occurs and the integrated server will803 #: automatically reload the application if changes in the code are804 #: detected.806 #: Whether debug mode is enabled. When using ``flask run`` to start807 #: the development server, an interactive debugger will be shown for808 #: unhandled exceptions, and the server will be reloaded when code809 #: changes. This maps to the :data:`DEBUG` config key. This is810 #: enabled when :attr:`env` is ``'development'`` and is overridden811 #: by the ``FLASK_DEBUG`` environment variable. It may not behave as812 #: expected if set in code.813 #:806 #: This value should only be configured by the :envvar:`FLASK_DEBUG`807 #: environment variable. Changing it by other means will not yield808 #: consistent results. The default value depends on the Flask809 #: environment and will be true for the development environment and false810 #: otherwise.814 #: **Do not enable debug mode when deploying in production.**815 #:816 #: Default: ``True`` if :attr:`env` is ``'development'``, or817 #: ``False`` otherwise.818 debug = property(_get_debug, _set_debug)819 del _get_debug, _set_debug820814 def _set_debug_value(self, value):815 self.config['DEBUG'] = value816 self.jinja_env.auto_reload = self.templates_auto_reload817821 def run(self, host=None, port=None, debug=None,822 load_dotenv=True, **options):823 """Runs the application on a local development server.824
1388 unmodified lines
modified:flask/helpers.py+13 added-8 removed
45 unmodified lines
46 if sep not in (None, '/'))474849def get_env():50 val = os.environ.get('FLASK_ENV')51 if not val:52 val = 'production'53 return val50 """Get the environment the app is running in, indicated by the51 :envvar:`FLASK_ENV` environment variable. The default is52 ``'production'``.53 """54 return os.environ.get('FLASK_ENV') or 'production'555657def get_debug_flag():58 """Get whether debug mode should be enabled for the app, indicated59 by the :envvar:`FLASK_DEBUG` environment variable. The default is60 ``True`` if :func:`.get_env` returns ``'development'``, or ``False``61 otherwise.62 """63 val = os.environ.get('FLASK_DEBUG')6465 if not val:59 env = get_env()60 if env == 'development':61 return True62 return False66 return get_env() == 'development'6768 return val.lower() not in ('0', 'false', 'no')697071def _endpoint_from_view_func(view_func):
963 unmodified lines