docs: :command:`pip`, :option:`--debug`
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by defuz · committed by defuz · parent 936e787 · Browse files · 14 files·+50 added−50 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
14 files+50 added−50 removed
- other:+50 added−50 removed
Provenance
- Commit
02694d6- Tree
bed200f- Author
defuz <defuz.net@gmail.com>- Committer
defuz <defuz.net@gmail.com>- Parent
936e787
14 files changed+50 added−50 removed
modified:docs/patterns/appfactories.rst+2 added-2 removed
88 unmodified lines89 Using Applications90 ------------------91 92 So to use such an application you then have to create the application93-first in a separate file otherwise the ``flask`` command won't be able93+first in a separate file otherwise the :command:`flask` command won't be able94 to find it. Here an example :file:`exampleapp.py` file that creates such95 an application::96 97 from yourapplication import create_app98 app = create_app('/path/to/config.cfg')99 100-It can then be used with the ``flask`` command::100+It can then be used with the :command:`flask` command::101 102 flask --app=exampleapp run103 104 Factory Improvements11 unmodified linesmodified:docs/patterns/celery.rst+1 added-1 removed
11 unmodified lines12 Installing Celery13 -----------------14 15 Celery is on the Python Package Index (PyPI), so it can be installed with16-standard Python tools like ``pip`` or ``easy_install``::16+standard Python tools like :command:`pip` or :command:`easy_install`::17 18 $ pip install celery19 20 Configuring Celery72 unmodified linesmodified:docs/patterns/distribute.rst+3 added-3 removed
16 unmodified lines17 provided by one package from another package. The best known feature of18 this system is the entry point support which allows one package to19 declare an "entry point" another package can hook into to extend the20 other package.21-- **installation manager**: `easy_install`, which comes with distribute22- can install other libraries for you. You can also use `pip`_ which23- sooner or later will replace `easy_install` which does more than just21+- **installation manager**: :command:`easy_install`, which comes with distribute22+ can install other libraries for you. You can also use :command:`pip`_ which23+ sooner or later will replace :command:`easy_install` which does more than just24 installing packages for you.25 26 Flask itself, and all the libraries you can find on the cheeseshop27 are distributed with either distribute, the older setuptools or distutils.139 unmodified linesmodified:docs/tutorial/dbinit.rst+3 added-3 removed
18 unmodified lines19 requires that we provide the path to the database which can introduce20 errors. It's a good idea to add a function that initializes the database21 for you to the application.22 23-To do this we can create a function and hook it into the ``flask`` command23+To do this we can create a function and hook it into the :command:`flask` command24 that initializes the database. Let me show you the code first. Just add25 this function below the `connect_db` function in :file:`flaskr.py`::26 27 def init_db():8 unmodified lines36 init_db()37 print 'Initialized the database.'38 39 The ``app.cli.command()`` decorator registers a new command with the40-``flask`` script. When the command executes Flask will automatically40+:command:`flask` script. When the command executes Flask will automatically41 create a application context for us bound to the right application.42 Within the function we can then access :attr:`flask.g` and other things as43 we would expect. When the script ends, the application context tears down44 and the database connection is released.12 unmodified lines57 On that cursor there is a method to execute a complete script. Finally we58 only have to commit the changes. SQLite 3 and other transactional59 databases will not commit unless you explicitly tell it to.60 61-Now it is possible to create a database with the ``flask`` script::61+Now it is possible to create a database with the :command:`flask` script::62 63 flask --app=flaskr initdb64 Initialized the database.65 7 unmodified linesmodified:docs/tutorial/setup.rst+1 added-1 removed
91 unmodified lines92 without problems. Do this with the following command::93 94 flask --app=flaskr --debug run95 96-The ``--debug`` flag enables or disables the interactive debugger. *Never96+The :option:`--debug` flag enables or disables the interactive debugger. *Never97 leave debug mode activated in a production system*, because it will allow98 users to execute code on the server!99 100 You will see a message telling you that server has started along with13 unmodified linesmodified:docs/cli.rst+10 added-10 removed
13 unmodified lines14 15 Basic Usage16 -----------17 18-After installation of Flask you will now find a ``flask`` script installed18+After installation of Flask you will now find a :command:`flask` script installed19 into your virtualenv. If you don't want to install Flask or you have a20 special use-case you can also use ``python -m flask`` to accomplish exactly21 the same.22 1 unmodified line24 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 desire so.27 28-For the ``flask`` script to work, an application needs to be discovered.28+For the :command:`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 the30+(``FLASK_APP``) or the :option:`--app` / :option:`-a` parameter. It should be the31 import path for your application or the path to a Python file. In the32 latter case Flask will attempt to setup the Python path for you33 automatically and discover the module name but that might not always work.34 26 unmodified lines61 62 Debug Flag63 ----------64 65-The ``flask`` script can be run with ``--debug`` or ``--no-debug`` to65+The :command:`flask` script can be run with :option:`--debug` or :option:`--no-debug` to66 automatically flip the debug flag of the application. This can also be67 configured by setting ``FLASK_DEBUG`` to ``1`` or ``0``.68 69 Running a Shell51 unmodified lines121 Factory Functions122 -----------------123 124 In case you are using factory functions to create your application (see125-:ref:`app-factories`) you will discover that the ``flask`` command cannot125+:ref:`app-factories`) you will discover that the :command:`flask` command cannot126 work with them directly. Flask won't be able to figure out how to127 instantiate your application properly by itself. Because of this reason128 the recommendation is to create a separate file that instantiates129 applications. This is by far not the only way to make this work. Another14 unmodified lines144 145 export YOURAPPLICATION_CONFIG=/path/to/config.cfg146 export FLASK_APP=/path/to/autoapp.py147 148-From this point onwards ``flask`` will find your application.148+From this point onwards :command:`flask` will find your application.149 150 .. _custom-scripts:151 152 Custom Scripts153 --------------154 155-While the most common way is to use the ``flask`` command, you can also155+While the most common way is to use the :command:`flask` command, you can also156 make your own "driver scripts". Since Flask uses click for the scripts157 there is no reason you cannot hook these scripts into any click158 application. There is one big caveat and that is, that commands159 registered to :attr:`Flask.cli` will expect to be (indirectly at least)1 unmodified line161 necessary so that the commands know which Flask application they have to162 work with.163 164 To understand why you might want custom scripts you need to understand how165-click finds and executes the Flask application. If you use the ``flask``165+click finds and executes the Flask application. If you use the :command:`flask`166 script you specify the application to work with on the command line or167 environment variable as an import name. This is simple but it has some168 limitations. Primarily it does not work with application factory169 functions (see :ref:`app-factories`).52 unmodified lines222 Whenever click now needs to operate on a Flask application it will223 call that function with the script info and ask for it to be created.224 4. In step 2 you could see that the config is passed to the actual225 creation function. This config comes from the :func:`script_info_option`226- decorator for the main script. It accepts a ``--config`` option and226+ decorator for the main script. It accepts a :option:`--config` option and227 then stores it in the script info so we can use it to create the228 application.229 5. All is rounded up by invoking the script.230 7 unmodified lines238 both provide custom commands to click as well as not loading your239 application unless it has to. The reason for this is added flexibility.240 241 This way an application can provide custom commands, but even in the242-absence of an application the ``flask`` script is still operational on a242+absence of an application the :command:`flask` script is still operational on a243 basic level. In addition to that it means that the individual commands244 have the option to avoid creating an instance of the Flask application245 unless required. This is very useful as it allows the server commands for246 instance to load the application on a first request instead of13 unmodified linesmodified:docs/extensions.rst+1 added-1 removed
6 unmodified lines7 Finding Extensions8 ------------------9 10 Flask extensions are listed on the `Flask Extension Registry`_ and can be11-downloaded with ``easy_install`` or ``pip``. If you add a Flask extension11+downloaded with :command:`easy_install` or :command:`pip`. If you add a Flask extension12 as dependency to your :file:`requirements.txt` or :file:`setup.py` file they are13 usually installed with a simple command or when your application installs.14 15 Using Extensions33 unmodified linesmodified:docs/installation.rst+9 added-9 removed
52 unmodified lines53 in your package manager. If you use Ubuntu, try::54 55 $ sudo apt-get install python-virtualenv56 57-If you are on Windows and don't have the `easy_install` command, you must57+If you are on Windows and don't have the :command:`easy_install` command, you must58 install it first. Check the :ref:`windows-easy-install` section for more59 information about how to do that. Once you have it installed, run the same60-commands as above, but without the `sudo` prefix.60+commands as above, but without the :command:`sudo` prefix.61 62 Once you have virtualenv installed, just fire up a shell and create63-your own environment. I usually create a project folder and a `venv`63+your own environment. I usually create a project folder and a :file:`venv`64 folder within::65 66 $ mkdir myproject67 $ cd myproject30 unmodified lines98 System-Wide Installation99 ------------------------100 101 This is possible as well, though I do not recommend it. Just run102-`pip` with root privileges::102+:command:`pip` with root privileges::103 104 $ sudo pip install Flask105 106 (On Windows systems, run it in a command-prompt window with administrator107-privileges, and leave out `sudo`.)107+privileges, and leave out :command:`sudo`.)108 109 110 Living on the Edge111 ------------------112 113 If you want to work with the latest version of Flask, there are two ways: you114-can either let `pip` pull in the development version, or you can tell114+can either let :command:`pip` pull in the development version, or you can tell115 it to operate on a git checkout. Either way, virtualenv is recommended.116 117 Get the git checkout in a new virtualenv and run in development mode::118 37 unmodified lines156 you can upgrade them by running::157 158 > pip install --upgrade pip setuptools159 160-Most often, once you pull up a command prompt you want to be able to type ``pip``161-and ``python`` which will run those things, but this might not automatically happen160+Most often, once you pull up a command prompt you want to be able to type :command:``pip``161+and :command:``python`` which will run those things, but this might not automatically happen162 on Windows, because it doesn't know where those executables are (give either a try!).163 164 To fix this, you should be able to navigate to your Python install directory165 (e.g ``C:\Python27``), then go to ``Tools``, then ``Scripts``; then find the166 ``win_add2path.py`` file and run that. Open a **new** Command Prompt and167-check that you can now just type ``python`` to bring up the interpreter.167+check that you can now just type :command:``python`` to bring up the interpreter.168 169 Finally, to install `virtualenv`_, you can simply run::170 171 > pip install virtualenv5 unmodified linesmodified:docs/quickstart.rst+8 added-8 removed
22 unmodified lines23 Just save it as :file:`hello.py` (or something similar) and run it with your Python24 interpreter. Make sure to not call your application :file:`flask.py` because this25 would conflict with Flask itself.26 27-To run the application you can either use the ``flask`` command or28-python's ``-m`` switch with Flask::27+To run the application you can either use the :command:`flask` command or28+python's :option:`-m` switch with Flask::29 30 $ flask -a hello run31 * Running on http://127.0.0.1:5000/32 45 unmodified lines78 79 What to do if the Server does not Start80 ---------------------------------------81 82-In case the ``python -m flask`` fails or ``flask`` does not exist,82+In case the ``python -m flask`` fails or :command:`flask` does not exist,83 there are multiple reasons this might be the case. First of all you need84 to look at the error message.85 86 Old Version of Flask87 ````````````````````88 89 Versions of Flask older than 1.0 use to have different ways to start the90-application. In short, the ``flask`` command did not exist, and90+application. In short, the :command:`flask` command did not exist, and91 neither did ``python -m flask``. In that case you have two options:92 either upgrade to newer Flask versions or have a look at the :ref:`server`93 docs to see the alternative method for running a server.94 95 Python older 2.796 ````````````````97 98 In case you have a version of Python older than 2.7 ``python -m flask``99-does not work. You can either use ``flask`` or ``python -m99+does not work. You can either use :command:`flask` or ``python -m100 flask.cli`` as an alternative. This is because Python before 2.7 does no101 permit packages to act as executable modules. For more information see102 :ref:`cli`.103 104 Invalid Import Name105 ```````````````````106 107-The ``-a`` argument to ``flask`` is the name of the module to import. In107+The :option:`-a` argument to :command:`flask` is the name of the module to import. In108 case that module is incorrectly named you will get an import error upon109 start (or if debug is enabled when you navigate to the application). It110 will tell you what it tried to import and why it failed.111 4 unmodified lines116 117 Debug Mode118 ----------119 120-The ``flask`` script is nice to start a local development server, but120+The :command:`flask` script is nice to start a local development server, but121 you would have to restart it manually after each change to your code.122 That is not very nice and Flask can do better. If you enable debug123 support the server will reload itself on code changes, and it will also124 provide you with a helpful debugger if things go wrong.125 126 There are different ways to enable the debug mode. The most obvious one127-is the ``--debug`` parameter to the ``flask`` command::127+is the :option:`--debug` parameter to the :command:`flask` command::128 129 flask --debug -a hello run130 131 This does the following things:762 unmodified linesmodified:docs/server.rst+5 added-5 removed
4 unmodified lines5 6 .. currentmodule:: flask7 8 Starting with Flask 1.0 there are multiple built-in ways to run a9-development server. The best one is the ``flask`` command line utility9+development server. The best one is the :command:`flask` command line utility10 but you can also continue using the :meth:`Flask.run` method.11 12 Command Line13 ------------14 15-The ``flask`` command line script (:ref:`cli`) is strongly recommende for15+The :command:`flask` command line script (:ref:`cli`) is strongly recommende for16 development because it provides a superior reload experience due to how it17 loads the application. The basic usage is like this::18 19 $ flask -a my_application --debug run20 21-This will enable the debugger, the reloader and then start the server on 21+This will enable the debugger, the reloader and then start the server on22 *http://localhost:5000/*.23 24 The individual features of the server can be controlled by passing more25 arguments to the ``run`` option. For instance the reloader can be5 unmodified lines31 -------32 33 The alternative way to start the application is through the34 :meth:`Flask.run` method. This will immediately launch a local server35-exactly the same way the ``flask`` script does.35+exactly the same way the :command:`flask` script does.36 37 Example::38 39 if __name__ == '__main__':40 app.run()41 42 This works well for the common case but it does not work well for43-development which is why from Flask 1.0 onwards the ``flask`` method is43+development which is why from Flask 1.0 onwards the :command:`flask` method is44 recommended. The reason for this is that due to how the reload mechanism45 works there are some bizarre side-effects (like executing certain code46 twice, sometimes crashing without message or dying when a syntax or47 import error happens).3 unmodified linesmodified:docs/upgrading.rst+2 added-2 removed
12 unmodified lines13 This section of the documentation enumerates all the changes in Flask from14 release to release and how you can change your code to have a painless15 updating experience.16 17-If you want to use the `easy_install` command to upgrade your Flask18-installation, make sure to pass it the ``-U`` parameter::17+If you want to use the :command:`easy_install` command to upgrade your Flask18+installation, make sure to pass it the :option:`-U` parameter::19 20 $ easy_install -U Flask21 22 .. _upgrading-to-10:360 unmodified linesmodified:flask/app.py+2 added-2 removed
521 unmodified lines522 endpoint='static',523 view_func=self.send_static_file)524 525 #: The click command line context for this application. Commands526- #: registered here show up in the ``flask`` command once the526+ #: registered here show up in the :command:`flask` command once the527 #: application has been discovered. The default commands are528 #: provided by Flask itself and can be overridden.529 #:530 #: This is an instance of a :class:`click.Group` object.241 unmodified lines772 traceback screen active, but disable code execution.773 774 It is not recommended to use this function for development with775 automatic reloading as this is badly supported. Instead you should776- be using the ``flask`` command line script's ``runserver``776+ be using the :command:`flask` command line script's ``runserver``777 support.778 779 .. admonition:: Keep in Mind780 1129 unmodified linesmodified:flask/cli.py+2 added-2 removed
265 unmodified lines266 For information as of why this is useful see :ref:`custom-scripts`.267 268 :param add_default_commands: if this is True then the default run and269 shell commands wil be added.270- :param add_app_option: adds the default ``--app`` option. This gets270+ :param add_app_option: adds the default :option:`--app` option. This gets271 automatically disabled if a `create_app`272 callback is defined.273- :param add_debug_option: adds the default ``--debug`` option.273+ :param add_debug_option: adds the default :option:`--debug` option.274 :param create_app: an optional callback that is passed the script info275 and returns the loaded app.276 """277 215 unmodified linesmodified:CHANGES+1 added-1 removed
26 unmodified lines27 can be configured with the new ``TEMPLATES_AUTO_RELOAD`` config key.28 - Added a workaround for a limitation in Python 3.3's namespace loader.29 - Added support for explicit root paths when using Python 3.3's namespace30 packages.31-- Added ``flask`` and the ``flask.cli`` module to start the local31+- Added :command:`flask` and the ``flask.cli`` module to start the local32 debug server through the click CLI system. This is recommended over the old33 ``flask.run()`` method as it works faster and more reliable due to a34 different design and also replaces ``Flask-Script``.35 - Error handlers that match specific classes are now checked first,503 unmodified lines