Skip to content
Myr

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

14 files+50 added−50 removed

modified:docs/patterns/appfactories.rst+2 added-2 removed
88 unmodified lines
89Using Applications90------------------9192So to use such an application you then have to create the application93first in a separate file otherwise the ``flask`` command won't be able93first in a separate file otherwise the :command:`flask` command won't be able94to find it. Here an example :file:`exampleapp.py` file that creates such95an application::9697 from yourapplication import create_app98 app = create_app('/path/to/config.cfg')99100It can then be used with the ``flask`` command::100It can then be used with the :command:`flask` command::101102 flask --app=exampleapp run103104Factory Improvements
11 unmodified lines
modified:docs/patterns/celery.rst+1 added-1 removed
11 unmodified lines
12Installing Celery13-----------------1415Celery is on the Python Package Index (PyPI), so it can be installed with16standard Python tools like ``pip`` or ``easy_install``::16standard Python tools like :command:`pip` or :command:`easy_install`::1718 $ pip install celery1920Configuring Celery
72 unmodified lines
modified:docs/patterns/distribute.rst+3 added-3 removed
16 unmodified lines
17 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.2526Flask itself, and all the libraries you can find on the cheeseshop27are distributed with either distribute, the older setuptools or distutils.
139 unmodified lines
modified:docs/tutorial/dbinit.rst+3 added-3 removed
18 unmodified lines
19requires that we provide the path to the database which can introduce20errors. It's a good idea to add a function that initializes the database21for you to the application.2223To do this we can create a function and hook it into the ``flask`` command23To do this we can create a function and hook it into the :command:`flask` command24that initializes the database. Let me show you the code first. Just add25this function below the `connect_db` function in :file:`flaskr.py`::2627 def init_db():
8 unmodified lines
36 init_db()37 print 'Initialized the database.'3839The ``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 automatically41create a application context for us bound to the right application.42Within the function we can then access :attr:`flask.g` and other things as43we would expect. When the script ends, the application context tears down44and the database connection is released.
12 unmodified lines
57On that cursor there is a method to execute a complete script. Finally we58only have to commit the changes. SQLite 3 and other transactional59databases will not commit unless you explicitly tell it to.6061Now it is possible to create a database with the ``flask`` script::61Now it is possible to create a database with the :command:`flask` script::6263 flask --app=flaskr initdb64 Initialized the database.65
7 unmodified lines
modified:docs/tutorial/setup.rst+1 added-1 removed
91 unmodified lines
92without problems. Do this with the following command::9394 flask --app=flaskr --debug run9596The ``--debug`` flag enables or disables the interactive debugger. *Never96The :option:`--debug` flag enables or disables the interactive debugger. *Never97leave debug mode activated in a production system*, because it will allow98users to execute code on the server!99100You will see a message telling you that server has started along with
13 unmodified lines
modified:docs/cli.rst+10 added-10 removed
13 unmodified lines
1415Basic Usage16-----------1718After installation of Flask you will now find a ``flask`` script installed18After installation of Flask you will now find a :command:`flask` script installed19into your virtualenv. If you don't want to install Flask or you have a20special use-case you can also use ``python -m flask`` to accomplish exactly21the same.22
1 unmodified line
24your Flask application's :attr:`Flask.cli` instance as well as some25built-in commands that are always there. Flask extensions can also26register more commands there if they desire so.2728For the ``flask`` script to work, an application needs to be discovered.28For the :command:`flask` script to work, an application needs to be discovered.29The 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 the31import path for your application or the path to a Python file. In the32latter case Flask will attempt to setup the Python path for you33automatically and discover the module name but that might not always work.34
26 unmodified lines
6162Debug Flag63----------6465The ``flask`` script can be run with ``--debug`` or ``--no-debug`` to65The :command:`flask` script can be run with :option:`--debug` or :option:`--no-debug` to66automatically flip the debug flag of the application. This can also be67configured by setting ``FLASK_DEBUG`` to ``1`` or ``0``.6869Running a Shell
51 unmodified lines
121Factory Functions122-----------------123124In 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 cannot126work with them directly. Flask won't be able to figure out how to127instantiate your application properly by itself. Because of this reason128the recommendation is to create a separate file that instantiates129applications. This is by far not the only way to make this work. Another
14 unmodified lines
144145 export YOURAPPLICATION_CONFIG=/path/to/config.cfg146 export FLASK_APP=/path/to/autoapp.py147148From this point onwards ``flask`` will find your application.148From this point onwards :command:`flask` will find your application.149150.. _custom-scripts:151152Custom Scripts153--------------154155While the most common way is to use the ``flask`` command, you can also155While the most common way is to use the :command:`flask` command, you can also156make your own "driver scripts". Since Flask uses click for the scripts157there is no reason you cannot hook these scripts into any click158application. There is one big caveat and that is, that commands159registered to :attr:`Flask.cli` will expect to be (indirectly at least)
1 unmodified line
161necessary so that the commands know which Flask application they have to162work with.163164To understand why you might want custom scripts you need to understand how165click finds and executes the Flask application. If you use the ``flask``165click finds and executes the Flask application. If you use the :command:`flask`166script you specify the application to work with on the command line or167environment variable as an import name. This is simple but it has some168limitations. Primarily it does not work with application factory169functions (see :ref:`app-factories`).
52 unmodified lines
222 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.2244. 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.2295. All is rounded up by invoking the script.230
7 unmodified lines
238both provide custom commands to click as well as not loading your239application unless it has to. The reason for this is added flexibility.240241This way an application can provide custom commands, but even in the242absence of an application the ``flask`` script is still operational on a242absence of an application the :command:`flask` script is still operational on a243basic level. In addition to that it means that the individual commands244have the option to avoid creating an instance of the Flask application245unless required. This is very useful as it allows the server commands for246instance to load the application on a first request instead of
13 unmodified lines
modified:docs/extensions.rst+1 added-1 removed
6 unmodified lines
7Finding Extensions8------------------910Flask extensions are listed on the `Flask Extension Registry`_ and can be11downloaded with ``easy_install`` or ``pip``. If you add a Flask extension11downloaded with :command:`easy_install` or :command:`pip`. If you add a Flask extension12as dependency to your :file:`requirements.txt` or :file:`setup.py` file they are13usually installed with a simple command or when your application installs.1415Using Extensions
33 unmodified lines
modified:docs/installation.rst+9 added-9 removed
52 unmodified lines
53in your package manager. If you use Ubuntu, try::5455 $ sudo apt-get install python-virtualenv5657If you are on Windows and don't have the `easy_install` command, you must57If you are on Windows and don't have the :command:`easy_install` command, you must58install it first. Check the :ref:`windows-easy-install` section for more59information about how to do that. Once you have it installed, run the same60commands as above, but without the `sudo` prefix.60commands as above, but without the :command:`sudo` prefix.6162Once you have virtualenv installed, just fire up a shell and create63your own environment. I usually create a project folder and a `venv`63your own environment. I usually create a project folder and a :file:`venv`64folder within::6566 $ mkdir myproject67 $ cd myproject
30 unmodified lines
98System-Wide Installation99------------------------100101This is possible as well, though I do not recommend it. Just run102`pip` with root privileges::102:command:`pip` with root privileges::103104 $ sudo pip install Flask105106(On Windows systems, run it in a command-prompt window with administrator107privileges, and leave out `sudo`.)107privileges, and leave out :command:`sudo`.)108109110Living on the Edge111------------------112113If you want to work with the latest version of Flask, there are two ways: you114can either let `pip` pull in the development version, or you can tell114can either let :command:`pip` pull in the development version, or you can tell115it to operate on a git checkout. Either way, virtualenv is recommended.116117Get the git checkout in a new virtualenv and run in development mode::118
37 unmodified lines
156you can upgrade them by running::157158 > pip install --upgrade pip setuptools159160Most often, once you pull up a command prompt you want to be able to type ``pip``161and ``python`` which will run those things, but this might not automatically happen160Most often, once you pull up a command prompt you want to be able to type :command:``pip``161and :command:``python`` which will run those things, but this might not automatically happen162on Windows, because it doesn't know where those executables are (give either a try!).163164To 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 and167check that you can now just type ``python`` to bring up the interpreter.167check that you can now just type :command:``python`` to bring up the interpreter.168169Finally, to install `virtualenv`_, you can simply run::170171 > pip install virtualenv
5 unmodified lines
modified:docs/quickstart.rst+8 added-8 removed
22 unmodified lines
23Just save it as :file:`hello.py` (or something similar) and run it with your Python24interpreter. Make sure to not call your application :file:`flask.py` because this25would conflict with Flask itself.2627To run the application you can either use the ``flask`` command or28python's ``-m`` switch with Flask::27To run the application you can either use the :command:`flask` command or28python's :option:`-m` switch with Flask::2930 $ flask -a hello run31 * Running on http://127.0.0.1:5000/32
45 unmodified lines
7879What to do if the Server does not Start80---------------------------------------8182In case the ``python -m flask`` fails or ``flask`` does not exist,82In case the ``python -m flask`` fails or :command:`flask` does not exist,83there are multiple reasons this might be the case. First of all you need84to look at the error message.8586Old Version of Flask87````````````````````8889Versions of Flask older than 1.0 use to have different ways to start the90application. In short, the ``flask`` command did not exist, and90application. In short, the :command:`flask` command did not exist, and91neither did ``python -m flask``. In that case you have two options:92either upgrade to newer Flask versions or have a look at the :ref:`server`93docs to see the alternative method for running a server.9495Python older 2.796````````````````9798In case you have a version of Python older than 2.7 ``python -m flask``99does not work. You can either use ``flask`` or ``python -m99does not work. You can either use :command:`flask` or ``python -m100flask.cli`` as an alternative. This is because Python before 2.7 does no101permit packages to act as executable modules. For more information see102:ref:`cli`.103104Invalid Import Name105```````````````````106107The ``-a`` argument to ``flask`` is the name of the module to import. In107The :option:`-a` argument to :command:`flask` is the name of the module to import. In108case that module is incorrectly named you will get an import error upon109start (or if debug is enabled when you navigate to the application). It110will tell you what it tried to import and why it failed.111
4 unmodified lines
116117Debug Mode118----------119120The ``flask`` script is nice to start a local development server, but120The :command:`flask` script is nice to start a local development server, but121you would have to restart it manually after each change to your code.122That is not very nice and Flask can do better. If you enable debug123support the server will reload itself on code changes, and it will also124provide you with a helpful debugger if things go wrong.125126There are different ways to enable the debug mode. The most obvious one127is the ``--debug`` parameter to the ``flask`` command::127is the :option:`--debug` parameter to the :command:`flask` command::128129 flask --debug -a hello run130131This does the following things:
762 unmodified lines
modified:docs/server.rst+5 added-5 removed
4 unmodified lines
56.. currentmodule:: flask78Starting with Flask 1.0 there are multiple built-in ways to run a9development server. The best one is the ``flask`` command line utility9development server. The best one is the :command:`flask` command line utility10but you can also continue using the :meth:`Flask.run` method.1112Command Line13------------1415The ``flask`` command line script (:ref:`cli`) is strongly recommende for15The :command:`flask` command line script (:ref:`cli`) is strongly recommende for16development because it provides a superior reload experience due to how it17loads the application. The basic usage is like this::1819 $ flask -a my_application --debug run2021This will enable the debugger, the reloader and then start the server on 21This will enable the debugger, the reloader and then start the server on22*http://localhost:5000/*.2324The individual features of the server can be controlled by passing more25arguments to the ``run`` option. For instance the reloader can be
5 unmodified lines
31-------3233The alternative way to start the application is through the34:meth:`Flask.run` method. This will immediately launch a local server35exactly the same way the ``flask`` script does.35exactly the same way the :command:`flask` script does.3637Example::3839 if __name__ == '__main__':40 app.run()4142This works well for the common case but it does not work well for43development which is why from Flask 1.0 onwards the ``flask`` method is43development which is why from Flask 1.0 onwards the :command:`flask` method is44recommended. The reason for this is that due to how the reload mechanism45works there are some bizarre side-effects (like executing certain code46twice, sometimes crashing without message or dying when a syntax or47import error happens).
3 unmodified lines
modified:docs/upgrading.rst+2 added-2 removed
12 unmodified lines
13This section of the documentation enumerates all the changes in Flask from14release to release and how you can change your code to have a painless15updating experience.1617If you want to use the `easy_install` command to upgrade your Flask18installation, make sure to pass it the ``-U`` parameter::17If you want to use the :command:`easy_install` command to upgrade your Flask18installation, make sure to pass it the :option:`-U` parameter::1920 $ easy_install -U Flask2122.. _upgrading-to-10:
360 unmodified lines
modified:flask/app.py+2 added-2 removed
521 unmodified lines
522 endpoint='static',523 view_func=self.send_static_file)524525 #: 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 lines
772 traceback screen active, but disable code execution.773774 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.778779 .. admonition:: Keep in Mind780
1129 unmodified lines
modified:flask/cli.py+2 added-2 removed
265 unmodified lines
266 For information as of why this is useful see :ref:`custom-scripts`.267268 :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 lines
modified:CHANGES+1 added-1 removed
26 unmodified lines
27 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