@@ -71,7 +71,7 @@ Run the Development Server
71
71
The :func: `run <cli.run_command> ` command will start the development server. It
72
72
replaces the :meth: `Flask.run ` method in most cases. ::
73
73
74
- $ flask run
74
+ $ flask --app hello run
75
75
* Serving Flask app "hello"
76
76
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
77
77
@@ -86,80 +86,56 @@ server tries to start. See :ref:`address-already-in-use` for how to
86
86
handle that.
87
87
88
88
89
- Open a Shell
90
- ------------
91
-
92
- To explore the data in your application, you can start an interactive Python
93
- shell with the :func: `shell <cli.shell_command> ` command. An application
94
- context will be active, and the app instance will be imported. ::
95
-
96
- $ flask shell
97
- Python 3.10.0 (default, Oct 27 2021, 06:59:51) [GCC 11.1.0] on linux
98
- App: example [production]
99
- Instance: /home/david/Projects/pallets/flask/instance
100
- >>>
101
-
102
- Use :meth: `~Flask.shell_context_processor ` to add other automatic imports.
103
-
104
-
105
- Environments
106
- ------------
107
-
108
- .. versionadded :: 1.0
89
+ Debug Mode
90
+ ~~~~~~~~~~
109
91
110
- The environment in which the Flask app executes is set by the
111
- ``FLASK_ENV `` environment variable. When using the ``flask `` command, it
112
- can also be set with the ``--env `` option. If not set it defaults to
113
- ``production ``. The other recognized environment is ``development ``.
114
- Flask and extensions may choose to enable behaviors based on the
115
- environment.
92
+ In debug mode, the ``flask run `` command will enable the interactive debugger and the
93
+ reloader by default, and make errors easier to see and debug. To enable debug mode, use
94
+ the ``--debug `` option.
116
95
117
- If the env is set to ``development ``, the ``flask `` command will enable
118
- debug mode and ``flask run `` will enable the interactive debugger and
119
- reloader.
96
+ .. code-block :: console
120
97
121
- .. code-block :: text
122
-
123
- $ flask --app hello --env development run
98
+ $ flask --app hello --debug run
124
99
* Serving Flask app "hello"
125
- * Environment: development
126
100
* Debug mode: on
127
101
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
128
102
* Restarting with inotify reloader
129
103
* Debugger is active!
130
104
* Debugger PIN: 223-456-919
131
105
132
106
133
- Watch Extra Files with the Reloader
134
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107
+ Watch and Ignore Files with the Reloader
108
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135
109
136
- When using development mode, the reloader will trigger whenever your
137
- Python code or imported modules change. The reloader can watch
138
- additional files with the ``--extra-files `` option. Multiple paths are
139
- separated with ``: ``, or ``; `` on Windows.
110
+ When using debug mode, the reloader will trigger whenever your Python code or imported
111
+ modules change. The reloader can watch additional files with the ``--extra-files ``
112
+ option. Multiple paths are separated with ``: ``, or ``; `` on Windows.
140
113
141
114
.. code-block :: text
142
115
143
116
$ flask run --extra-files file1:dirA/file2:dirB/
144
117
* Running on http://127.0.0.1:8000/
145
118
* Detected change in '/path/to/file1', reloading
146
119
120
+ The reloader can also ignore files using :mod: `fnmatch ` patterns with the
121
+ ``--exclude-patterns `` option. Multiple patterns are separated with ``: ``, or ``; `` on
122
+ Windows.
147
123
148
- Ignore files with the Reloader
149
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150
124
151
- The reloader can also ignore files using :mod: `fnmatch ` patterns with
152
- the ``--exclude-patterns `` option. Multiple patterns are separated with
153
- ``: ``, or ``; `` on Windows.
125
+ Open a Shell
126
+ ------------
154
127
128
+ To explore the data in your application, you can start an interactive Python
129
+ shell with the :func: `shell <cli.shell_command> ` command. An application
130
+ context will be active, and the app instance will be imported. ::
155
131
156
- Debug Mode
157
- ----------
132
+ $ flask shell
133
+ Python 3.10.0 (default, Oct 27 2021, 06:59:51) [GCC 11.1.0] on linux
134
+ App: example [production]
135
+ Instance: /home/david/Projects/pallets/flask/instance
136
+ >>>
158
137
159
- Debug mode will be enabled when the execution environment is
160
- ``development ``, as described above. If you want to control debug mode
161
- separately, use the ``--debug/--no-debug `` option or the ``FLASK_DEBUG ``
162
- environment variable.
138
+ Use :meth: `~Flask.shell_context_processor ` to add other automatic imports.
163
139
164
140
165
141
.. _dotenv :
@@ -552,53 +528,36 @@ script is available. Note that you don't need to set ``--app``. ::
552
528
PyCharm Integration
553
529
-------------------
554
530
555
- PyCharm Professional provides a special Flask run configuration. For
556
- the Community Edition, we need to configure it to call the `` flask run ``
557
- CLI command with the correct environment variables . These instructions
558
- should be similar for any other IDE you might want to use.
531
+ PyCharm Professional provides a special Flask run configuration to run the development
532
+ server. For the Community Edition, and for other commands besides `` run ``, you need to
533
+ create a custom run configuration . These instructions should be similar for any other
534
+ IDE you use.
559
535
560
- In PyCharm, with your project open, click on *Run * from the menu bar and
561
- go to *Edit Configurations *. You'll be greeted by a screen similar to
562
- this:
536
+ In PyCharm, with your project open, click on *Run * from the menu bar and go to *Edit
537
+ Configurations *. You'll see a screen similar to this:
563
538
564
- .. image :: _static/pycharm-runconfig .png
539
+ .. image :: _static/pycharm-run-config .png
565
540
:align: center
566
541
:class: screenshot
567
- :alt: Screenshot of PyCharms's run configuration settings.
568
-
569
- There's quite a few options to change, but once we've done it for one
570
- command, we can easily copy the entire configuration and make a single
571
- tweak to give us access to other commands, including any custom ones you
572
- may implement yourself.
573
-
574
- Click the + (*Add New Configuration *) button and select *Python *. Give
575
- the configuration a name such as "flask run". For the ``flask run ``
576
- command, check "Single instance only" since you can't run the server
577
- more than once at the same time.
542
+ :alt: Screenshot of PyCharm run configuration.
578
543
579
- Select *Module name * from the dropdown (**A **) then input ``flask ``.
544
+ Once you create a configuration for the ``flask run ``, you can copy and change it to
545
+ call any other command.
580
546
581
- The *Parameters * field (**B **) is set to the CLI command to execute
582
- (with any arguments). In this example we use ``run ``, which will run
583
- the development server.
547
+ Click the *+ (Add New Configuration) * button and select *Python *. Give the configuration
548
+ a name such as "flask run".
584
549
585
- You can skip this next step if you're using :ref: `dotenv `. We need to
586
- add an environment variable (**C **) to identify our application. Click
587
- on the browse button and add an entry with ``FLASK_APP `` on the left and
588
- the Python import or file on the right (``hello `` for example). Add an
589
- entry with ``FLASK_ENV `` and set it to ``development ``.
550
+ Click the *Script path * dropdown and change it to *Module name *, then input ``flask ``.
590
551
591
- Next we need to set the working directory (**D **) to be the folder where
592
- our application resides.
552
+ The *Parameters * field is set to the CLI command to execute along with any arguments.
553
+ This example uses ``--app hello --debug run ``, which will run the development server in
554
+ debug mode. ``--app hello `` should be the import or file with your Flask app.
593
555
594
- If you have installed your project as a package in your virtualenv, you
595
- may untick the *PYTHONPATH * options (**E **). This will more accurately
596
- match how you deploy the app later.
556
+ If you installed your project as a package in your virtualenv, you may uncheck the
557
+ *PYTHONPATH * options. This will more accurately match how you deploy later.
597
558
598
- Click *Apply * to save the configuration, or *OK * to save and close the
599
- window. Select the configuration in the main PyCharm window and click
600
- the play button next to it to run the server.
559
+ Click *OK * to save and close the configuration. Select the configuration in the main
560
+ PyCharm window and click the play button next to it to run the server.
601
561
602
- Now that we have a configuration which runs ``flask run `` from within
603
- PyCharm, we can copy that configuration and alter the *Script * argument
604
- to run a different CLI command, e.g. ``flask shell ``.
562
+ Now that you have a configuration for ``flask run ``, you can copy that configuration and
563
+ change the *Parameters * argument to run a different CLI command.
0 commit comments