Docs: fixes
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Julen Ruiz Aizpuru · committed by Julen Ruiz Aizpuru · parent 1b77a3f · Browse files · 1 file·+16 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+16 added−17 removed
- other:+16 added−17 removed
Provenance
- Commit
a700cb2- Tree
65e2a28- Author
Julen Ruiz Aizpuru <julenx@gmail.com>- Committer
Julen Ruiz Aizpuru <julenx@gmail.com>- Parent
1b77a3f
1 file changed+16 added−17 removed
modified:docs/cli.rst+16 added-17 removed
21 unmodified lines22 23 The way this script works is by providing access to all the commands on24 your Flask application's :attr:`Flask.cli` instance as well as some25 built-in commands that are always there. Flask extensions can also26-register more commands there if they so desire.26+register more commands there if they desire so.27 28 For the ``flask`` script to work, an application needs to be discovered.29 The two most common ways are either an environment variable30 (``FLASK_APP``) or the ``--app`` / ``-a`` parameter. It should be the74 unmodified lines105 106 In case you are using factory functions to create your application (see107 :ref:`app-factories`) you will discover that the ``flask`` command cannot108 work with them directly. Flask won't be able to figure out how to109-instanciate your application properly by itself. Because of this reason110-the recommendation is to create a separate file that instanciates109+instantiate your application properly by itself. Because of this reason110+the recommendation is to create a separate file that instantiates111 applications. This is by far not the only way to make this work. Another112 is the :ref:`custom-scripts` support.113 114 For instance if you have a factory function that creates an application115 from a filename you could make a separate file that creates such an116 application from an environment variable.117 118-For instance this could be a file named ``autoapp.py`` with these119-contents::118+This could be a file named ``autoapp.py`` with these contents::119 120 import os121 from yourapplication import create_app122 app = create_app(os.environ['YOURAPPLICATION_CONFIG'])37 unmodified lines160 We won't go into detail now about the differences but if you are curious161 you can have a look at the :ref:`script-info-object` section to learn all162 about it.163 165-To explain all of this here an example ``manage.py`` script that manages a166-hypothetical wiki application. We will go through the details164+To explain all of this, here is an example ``manage.py`` script that165+manages a hypothetical wiki application. We will go through the details166 afterwards::167 168 import click169 from flask.cli import FlaskGroup, script_info_option13 unmodified lines183 184 That's a lot of code for not much, so let's go through all parts step by185 step.186 188-1. At first we import regular ``click`` as well as the click extensions187+1. First we import the ``click`` library as well as the click extensions188 from the ``flask.cli`` package. Primarily we are here interested189 in the :class:`~flask.cli.FlaskGroup` click group and the190 :func:`~flask.cli.script_info_option` decorator.191 2. The next thing we do is defining a function that is invoked with the193- script info object (:ref:`script-info-object`) from flask and it's192+ script info object (:ref:`script-info-object`) from Flask and its193 purpose is to fully import and create the application. This can194 either directly import an application object or create it (see195 :ref:`app-factories`).196 1 unmodified line198 script info that can be filled by options or through other means. We199 will come back to this later.200 3. Next step is to create a :class:`FlaskGroup`. In this case we just201 make an empty function with a help doc string that just does nothing203- and then pass the ``create_wiki_app`` function as factory function.202+ and then pass the ``create_wiki_app`` function as a factory function.203 205- Whenever click now needs to operate on a flask application it will204+ Whenever click now needs to operate on a Flask application it will205 call that function with the script info and ask for it to be created.206 4. In step 2 you could see that the config is passed to the actual207 creation function. This config comes from the :func:`script_info_option`208 decorator for the main script. It accepts a ``--config`` option and12 unmodified lines221 application unless it has to. The reason for this is added flexibility.222 223 This way an application can provide custom commands, but even in the224 absence of an application the ``flask`` script is still operational on a226-basic level. In addition to that does it mean that the individual227-commands have the option to not create an instance of the Flask228-application unless required. This is very useful as it allows the server229-command for instance, the load the application on first request instead of230-immediately to give a better debug experience.225+basic level. In addition to that it means that the individual commands226+have the option to avoid creating an instance of the Flask application227+unless required. This is very useful as it allows the server commands for228+instance to load the application on a first request instead of229+immediately, therefore giving a better debug experience.230 231 All of this is provided through the :class:`flask.cli.ScriptInfo` object232 and some helper utilities around. The basic way it operates is that when233 the :class:`flask.cli.FlaskGroup` executes as a script it creates a script3 unmodified lines237 238 One Flask actually needs the individual Flask application it will invoke239 the :meth:`flask.cli.ScriptInfo.load_app` method. This happens when the240 server starts, when the shell is launched or when the script looks for an242-application provided click command.241+application-provided click command.