Skip to content
Myr

remove FLASK_ENV from docs

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 ef95998 · Browse files · 7 files+84 added−188 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+84 added−188 removed

  • other:+84 added−188 removed

7 files+84 added−188 removed

modified:docs/tutorial/factory.rst+3 added-4 removed
125 unmodified lines
126-------------------127128Now you can run your application using the ``flask`` command. From the129terminal, tell Flask where to find your application, then run it in130development mode. Remember, you should still be in the top-level130debug mode. Remember, you should still be in the top-level131``flask-tutorial`` directory, not the ``flaskr`` package.132133Development mode shows an interactive debugger whenever a page raises an133Debug mode shows an interactive debugger whenever a page raises an134exception, and restarts the server whenever you make changes to the135code. You can leave it running and just reload the browser page as you136follow the tutorial.137138.. code-block:: text139140 $ flask --app flaskr --env development run140 $ flask --app flaskr --debug run141142You'll see output similar to this:143144.. code-block:: text145146 * Serving Flask app "flaskr"147 * Environment: development147 * Debug mode: on148 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)149 * Restarting with stat150 * Debugger is active!
12 unmodified lines
modified:docs/cli.rst+27 added-51 removed
69 unmodified lines
7071The :func:`run <cli.run_command>` command will start the development server. It72replaces the :meth:`Flask.run` method in most cases. ::7374 $ flask run74 $ flask --app hello run75 * Serving Flask app "hello"76 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)7778.. warning:: Do not use this command to run your application in production.
6 unmodified lines
85server tries to start. See :ref:`address-already-in-use` for how to86handle that.878889Open a Shell90------------89Debug Mode90~~~~~~~~~~9192To explore the data in your application, you can start an interactive Python93shell with the :func:`shell <cli.shell_command>` command. An application94context will be active, and the app instance will be imported. ::92In debug mode, the ``flask run`` command will enable the interactive debugger and the93reloader by default, and make errors easier to see and debug. To enable debug mode, use94the ``--debug`` option.9596 $ flask shell97 Python 3.10.0 (default, Oct 27 2021, 06:59:51) [GCC 11.1.0] on linux98 App: example [production]99 Instance: /home/david/Projects/pallets/flask/instance100 >>>96.. code-block:: console97102Use :meth:`~Flask.shell_context_processor` to add other automatic imports.103104105Environments106------------107108.. versionadded:: 1.0109110The environment in which the Flask app executes is set by the111``FLASK_ENV`` environment variable. When using the ``flask`` command, it112can also be set with the ``--env`` option. If not set it defaults to113``production``. The other recognized environment is ``development``.114Flask and extensions may choose to enable behaviors based on the115environment.116117If the env is set to ``development``, the ``flask`` command will enable118debug mode and ``flask run`` will enable the interactive debugger and119reloader.120121.. code-block:: text122123 $ flask --app hello --env development run98 $ flask --app hello --debug run99 * Serving Flask app "hello"125 * Environment: development100 * Debug mode: on101 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)102 * Restarting with inotify reloader103 * Debugger is active!104 * Debugger PIN: 223-456-919105106133Watch Extra Files with the Reloader134~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~107Watch and Ignore Files with the Reloader108~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~109136When using development mode, the reloader will trigger whenever your137Python code or imported modules change. The reloader can watch138additional files with the ``--extra-files`` option. Multiple paths are139separated with ``:``, or ``;`` on Windows.110When using debug mode, the reloader will trigger whenever your Python code or imported111modules change. The reloader can watch additional files with the ``--extra-files``112option. Multiple paths are separated with ``:``, or ``;`` on Windows.113114.. code-block:: text115116 $ flask run --extra-files file1:dirA/file2:dirB/117 * Running on http://127.0.0.1:8000/118 * Detected change in '/path/to/file1', reloading119120The reloader can also ignore files using :mod:`fnmatch` patterns with the121``--exclude-patterns`` option. Multiple patterns are separated with ``:``, or ``;`` on122Windows.123148Ignore files with the Reloader149~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~124151The reloader can also ignore files using :mod:`fnmatch` patterns with152the ``--exclude-patterns`` option. Multiple patterns are separated with153``:``, or ``;`` on Windows.125Open a Shell126------------127128To explore the data in your application, you can start an interactive Python129shell with the :func:`shell <cli.shell_command>` command. An application130context will be active, and the app instance will be imported. ::131156Debug Mode157----------132 $ flask shell133 Python 3.10.0 (default, Oct 27 2021, 06:59:51) [GCC 11.1.0] on linux134 App: example [production]135 Instance: /home/david/Projects/pallets/flask/instance136 >>>137159Debug mode will be enabled when the execution environment is160``development``, as described above. If you want to control debug mode161separately, use the ``--debug/--no-debug`` option or the ``FLASK_DEBUG``162environment variable.138Use :meth:`~Flask.shell_context_processor` to add other automatic imports.139140141.. _dotenv:142
421 unmodified lines
modified:docs/config.rst+25 added-43 removed
40 unmodified lines
41 SECRET_KEY='192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf'42 )434445Environment and Debug Features46------------------------------45Debug Mode46----------4748The :data:`ENV` and :data:`DEBUG` config values are special because they49may behave inconsistently if changed after the app has begun setting up.50In order to set the environment and debug mode reliably, pass options to51the ``flask`` command or use environment variables.48The :data:`DEBUG` config value is special because it may behave inconsistently if49changed after the app has begun setting up. In order to set debug mode reliably, use the50``--debug`` option on the ``flask`` command.``flask run`` will use the interactive51debugger and reloader by default in debug mode.5253The execution environment is used to indicate to Flask, extensions, and54other programs, like Sentry, what context Flask is running in. It is55controlled with the ``FLASK_ENV`` environment variable, or the56``--env`` option when using the ``flask`` command, and defaults to57``production``.5859Setting ``--env development`` will enable debug mode. ``flask run`` will60use the interactive debugger and reloader by default in debug mode. To61control this separately from the environment, use the62``--debug/--no-debug`` option or the ``FLASK_DEBUG`` environment63variable.6465To switch Flask to the development environment and enable debug mode,66set ``--env``:6753.. code-block:: text5470 $ flask --app hello --env development run55 $ flask --app hello --debug run5672Using the options or environment variables as described above is73recommended. While it is possible to set :data:`ENV` and :data:`DEBUG`74in your config or code, this is strongly discouraged. They can't be read75early by the ``flask`` command, and some systems or extensions may have76already configured themselves based on a previous value.57Using the option is recommended. While it is possible to set :data:`DEBUG` in your58config or code, this is strongly discouraged. It can't be read early by the ``flask``59command, and some systems or extensions may have already configured themselves based on60a previous value.616263Builtin Configuration Values64----------------------------
1 unmodified line
66The following configuration values are used internally by Flask:6768.. py:data:: ENV6986 What environment the app is running in. Flask and extensions may87 enable behaviors based on the environment, such as enabling debug88 mode. The :attr:`~flask.Flask.env` attribute maps to this config89 key. This is set by the :envvar:`FLASK_ENV` environment variable and90 may not behave as expected if set in code.70 What environment the app is running in. The :attr:`~flask.Flask.env` attribute maps71 to this config key.7292 **Do not enable development when deploying in production.**9373 Default: ``'production'``7475 .. deprecated:: 2.276 Will be removed in Flask 2.3. Use ``--debug`` instead.7778 .. versionadded:: 1.07980.. py:data:: DEBUG81100 Whether debug mode is enabled. When using ``flask run`` to start the101 development server, an interactive debugger will be shown for102 unhandled exceptions, and the server will be reloaded when code103 changes. The :attr:`~flask.Flask.debug` attribute maps to this104 config key. This is enabled when :data:`ENV` is ``'development'``105 and is overridden by the ``FLASK_DEBUG`` environment variable. It106 may not behave as expected if set in code.82 Whether debug mode is enabled. When using ``flask run`` to start the development83 server, an interactive debugger will be shown for unhandled exceptions, and the84 server will be reloaded when code changes. The :attr:`~flask.Flask.debug` attribute85 maps to this config key. This is set with the ``FLASK_DEBUG`` environment variable.86 It may not behave as expected if set in code.8788 **Do not enable debug mode when deploying in production.**89110 Default: ``True`` if :data:`ENV` is ``'development'``, or ``False``111 otherwise.90 Default: ``False``9192.. py:data:: TESTING9394 Enable testing mode. Exceptions are propagated rather than handled by the
291 unmodified lines
386 ``JSONIFY_MIMETYPE``, and ``JSONIFY_PRETTYPRINT_REGULAR`` will be387 removed in Flask 2.3. The default ``app.json`` provider has388 equivalent attributes instead.389390.. versionchanged:: 2.2391 ``ENV`` will be removed in Flask 2.3. Use ``--debug`` instead.392393394Configuring from Python Files395-----------------------------396397Configuration becomes more useful if you can store it in a separate file,
387 unmodified lines
modified:docs/debugging.rst+8 added-14 removed
37 unmodified lines
38 browser. It is protected by a pin, but still represents a major39 security risk. Do not run the development server or debugger in a40 production environment.4142To enable the debugger, run the development server with the environment43set to ``development``. This puts Flask in debug mode, which changes how44it handles some errors, and enables the debugger and reloader.42The debugger is enabled by default when the development server is run in debug mode.4344.. code-block:: text4548 $ flask --app hello --env development run46 $ flask --app hello --debug run4750``FLASK_ENV`` can also be set as an environment variable. When running51from Python code, passing ``debug=True`` enables debug mode, which is52mostly equivalent. Debug mode can be controlled separately from the48When running from Python code, passing ``debug=True`` enables debug mode, which is49mostly equivalent.53environment with the ``--debug/--no-debug`` option or the54``FLASK_DEBUG`` environment variable.5051.. code-block:: python5253 app.run(debug=True)5460:doc:`/server` and :doc:`/cli` have more information about running the61debugger, debug mode, and development mode. More information about the62debugger can be found in the `Werkzeug documentation63<https://werkzeug.palletsprojects.com/debug/>`__.55:doc:`/server` and :doc:`/cli` have more information about running the debugger and56debug mode. More information about the debugger can be found in the `Werkzeug57documentation <https://werkzeug.palletsprojects.com/debug/>`__.585960External Debuggers61------------------
9 unmodified lines
71which can interfere.7273.. code-block:: text7481 $ flask --app hello --env development run --no-debugger --no-reload75 $ flask --app hello --debug run --no-debugger --no-reload7677When running from Python:7879.. code-block:: python
8 unmodified lines
modified:docs/quickstart.rst+3 added-6 removed
102 unmodified lines
103 browser. It is protected by a pin, but still represents a major104 security risk. Do not run the development server or debugger in a105 production environment.106107To enable all development features, set the ``--env`` option to108``development``.107To enable debug mode, use the ``--debug`` option.108109.. code-block:: text110112 $ flask --app hello --env development run111 $ flask --app hello --debug run112 * Serving Flask app 'hello'114 * Environment: development113 * Debug mode: on114 * Running on http://127.0.0.1:5000 (Press CTRL+C to quit)115 * Restarting with stat116 * Debugger is active!117 * Debugger PIN: nnn-nnn-nnn118119See also:120123- :doc:`/server` and :doc:`/cli` for information about running in124 development mode.121- :doc:`/server` and :doc:`/cli` for information about running in debug mode.122- :doc:`/debugging` for information about using the built-in debugger123 and other debuggers.124- :doc:`/logging` and :doc:`/errorhandling` to log errors and display125 nice error pages.
774 unmodified lines
modified:docs/server.rst+17 added-69 removed
1 unmodified line
23Development Server4==================56Flask provides a ``run`` command to run the application with a7development server. In development mode, this server provides an8interactive debugger and will reload when code is changed.6Flask provides a ``run`` command to run the application with a development server. In7debug mode, this server provides an interactive debugger and will reload when code is8changed.910.. warning::1112 Do not use the development server when deploying to production. It
4 unmodified lines
1718Command Line19------------2021The ``flask run`` command line script is the recommended way to run the22development server. Use the ``--app`` option to point to your23application, and the ``--env development`` option to fully enable24development mode.21The ``flask run`` CLI command is the recommended way to run the development server. Use22the ``--app`` option to point to your application, and the ``--debug`` option to enable23debug mode.2425.. code-block:: text2628 $ flask --app hello --env development run27 $ flask --app hello --debug run2830These options (and any others) can also be set using environment31variables.29This enables debug mode, including the interactive debugger and reloader, and then30starts the server on http://localhost:5000/. Use ``flask run --help`` to see the31available options, and :doc:`/cli` for detailed instructions about configuring and using32the CLI.3333.. tabs::3435 .. group-tab:: Bash3637 .. code-block:: text3839 $ export FLASK_APP=hello40 $ export FLASK_ENV=development41 $ flask run4243 .. group-tab:: Fish4445 .. code-block:: text4647 $ set -x FLASK_APP hello48 $ export FLASK_ENV=development49 $ flask run5051 .. group-tab:: CMD5253 .. code-block:: text5455 > set FLASK_APP=hello56 > set FLASK_ENV=development57 > flask run5859 .. group-tab:: Powershell6061 .. code-block:: text6263 > $env:FLASK_APP = "hello"64 > $env:FLASK_ENV = "development"65 > flask run6667This enables the development environment, including the interactive68debugger and reloader, and then starts the server on69http://localhost:5000/. Use ``flask run --help`` to see the available70options, and :doc:`/cli` for detailed instructions about configuring71and using the CLI.7273.. note::7475 Debug mode can be controlled separately from the development76 environment with the ``--debug/--no-debug`` option or the77 ``FLASK_DEBUG`` environment variable. This is how older versions of78 Flask worked. You should prefer setting the development environment79 as shown above.808135.. _address-already-in-use:3637Address already in use38~~~~~~~~~~~~~~~~~~~~~~
57 unmodified lines
9697In Code98-------99147As an alternative to the ``flask run`` command, the development server148can also be started from Python with the :meth:`Flask.run` method. This149method takes arguments similar to the CLI options to control the server.150The main difference from the CLI command is that the server will crash151if there are errors when reloading.100The development server can also be started from Python with the :meth:`Flask.run`101method. This method takes arguments similar to the CLI options to control the server.102The main difference from the CLI command is that the server will crash if there are103errors when reloading. ``debug=True`` can be passed to enable debug mode.104153``debug=True`` can be passed to enable the debugger and reloader, but154the ``FLASK_ENV=development`` environment variable is still required to155fully enable development mode.105Place the call in a main block, otherwise it will interfere when trying to import and106run the application with a production server later.107157Place the call in a main block, otherwise it will interfere when trying158to import and run the application with a production server later.159108.. code-block:: python109110 if __name__ == "__main__":111 app.run(debug=True)
4 unmodified lines
modified:examples/tutorial/README.rst+1 added-1 removed
46 unmodified lines
4748.. code-block:: text4950 $ flask --app flaskr init-db51 $ flask --app flaskr --env development run51 $ flask --app flaskr --debug run5253Open http://127.0.0.1:5000 in a browser.5455
13 unmodified lines