Skip to content
Myr

Add prefix for all commands in documentation (#2877)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Add prefix for commands in docs * Add prefix for commands in example's README

authored by Grey Li · committed by Hsiaoming Yang · parent b9b88b0 · Browse files · 19 files+112 added−112 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

19 files+112 added−112 removed

  • other:+112 added−112 removed

19 files+112 added−112 removed

modified:docs/deploying/fastcgi.rst+1 added-1 removed
47 unmodified lines
48can execute it:4950.. sourcecode:: text5152 # chmod +x /var/www/yourapplication/yourapplication.fcgi52 $ chmod +x /var/www/yourapplication/yourapplication.fcgi5354Configuring Apache55------------------56
184 unmodified lines
modified:docs/deploying/mod_wsgi.rst+3 added-3 removed
25 unmodified lines
26follows:2728.. sourcecode:: text2930 # apt-get install libapache2-mod-wsgi30 $ apt-get install libapache2-mod-wsgi3132If you are using a yum based distribution (Fedora, OpenSUSE, etc..) you33can install it as follows:3435.. sourcecode:: text3637 # yum install mod_wsgi37 $ yum install mod_wsgi3839On FreeBSD install `mod_wsgi` by compiling the `www/mod_wsgi` port or by40using pkg_add:4142.. sourcecode:: text4344 # pkg install ap22-mod_wsgi244 $ pkg install ap22-mod_wsgi24546If you are using pkgsrc you can install `mod_wsgi` by compiling the47`www/ap2-wsgi` package.48
169 unmodified lines
modified:docs/deploying/wsgi-standalone.rst+5 added-5 removed
13 unmodified lines
14`Gunicorn`_ 'Green Unicorn' is a WSGI HTTP Server for UNIX. It's a pre-fork15worker model ported from Ruby's Unicorn project. It supports both `eventlet`_16and `greenlet`_. Running a Flask application on this server is quite simple::1718 gunicorn myproject:app18 $ gunicorn myproject:app1920`Gunicorn`_ provides many command-line options -- see ``gunicorn -h``.21For example, to run a Flask application with 4 worker processes (``-w224``) binding to localhost port 4000 (``-b 127.0.0.1:4000``)::2324 gunicorn -w 4 -b 127.0.0.1:4000 myproject:app24 $ gunicorn -w 4 -b 127.0.0.1:4000 myproject:app2526.. _Gunicorn: http://gunicorn.org/27.. _eventlet: http://eventlet.net/28.. _greenlet: https://greenlet.readthedocs.io/en/latest/
5 unmodified lines
34which makes it more complicated to setup than gunicorn.3536Running `uWSGI HTTP Router`_::3738 uwsgi --http 127.0.0.1:5000 --module myproject:app38 $ uwsgi --http 127.0.0.1:5000 --module myproject:app3940For a more optimized setup, see :doc:`configuring uWSGI and NGINX <uwsgi>`.4142.. _uWSGI: http://uwsgi-docs.readthedocs.io/en/latest/
23 unmodified lines
66non-blocking event-driven networking library. Twisted Web comes with a67standard WSGI container which can be controlled from the command line using68the ``twistd`` utility::6970 twistd web --wsgi myproject.app70 $ twistd web --wsgi myproject.app7172This example will run a Flask application called ``app`` from a module named73``myproject``.74
1 unmodified line
76as well; see ``twistd -h`` and ``twistd web -h`` for more information. For77example, to run a Twisted Web server in the foreground, on port 8080, with an78application from ``myproject``::7980 twistd -n web --port tcp:8080 --wsgi myproject.app80 $ twistd -n web --port tcp:8080 --wsgi myproject.app8182.. _Twisted: https://twistedmatrix.com/83.. _Twisted Web: https://twistedmatrix.com/trac/wiki/TwistedWeb84
65 unmodified lines
modified:docs/patterns/appfactories.rst+4 added-4 removed
89 unmodified lines
90------------------9192To run such an application, you can use the :command:`flask` command::9394 export FLASK_APP=myapp95 flask run94 $ export FLASK_APP=myapp95 $ flask run96 97Flask will automatically detect the factory (``create_app`` or ``make_app``) 98in ``myapp``. You can also pass arguments to the factory like this::99100 export FLASK_APP="myapp:create_app('dev')"101 flask run100 $ export FLASK_APP="myapp:create_app('dev')"101 $ flask run102 103Then the ``create_app`` factory in ``myapp`` is called with the string104``'dev'`` as the argument. See :doc:`/cli` for more detail.105
12 unmodified lines
modified:docs/patterns/packages.rst+4 added-4 removed
59 unmodified lines
6061In order to run the application you need to export an environment variable62that tells Flask where to find the application instance::6364 export FLASK_APP=yourapplication64 $ export FLASK_APP=yourapplication6566If you are outside of the project directory make sure to provide the exact67path to your application directory. Similarly you can turn on the68development features like this::6970 export FLASK_ENV=development70 $ export FLASK_ENV=development7172In order to install and run the application you need to issue the following73commands::7475 pip install -e .76 flask run75 $ pip install -e .76 $ flask run7778What did we gain from this? Now we can restructure the application a bit79into multiple modules. The only thing you have to remember is the80following quick checklist:
63 unmodified lines
modified:docs/tutorial/database.rst+1 added-1 removed
202 unmodified lines
203Run the ``init-db`` command:204205.. code-block:: none206207 flask init-db207 $ flask init-db208 Initialized the database.209210There will now be a ``flaskr.sqlite`` file in the ``instance`` folder in211your project.
2 unmodified lines
modified:docs/tutorial/deploy.rst+8 added-8 removed
19 unmodified lines
20is installed first:2122.. code-block:: none2324 pip install wheel24 $ pip install wheel2526Running ``setup.py`` with Python gives you a command line tool to issue27build-related commands. The ``bdist_wheel`` command will build a wheel28distribution file.2930.. code-block:: none3132 python setup.py bdist_wheel32 $ python setup.py bdist_wheel3334You can find the file in ``dist/flaskr-1.0.0-py3-none-any.whl``. The35file name is the name of the project, the version, and some tags about36the file can install.
3 unmodified lines
40file with ``pip``.4142.. code-block:: none4344 pip install flaskr-1.0.0-py3-none-any.whl44 $ pip install flaskr-1.0.0-py3-none-any.whl4546Pip will install your project along with its dependencies.4748Since this is a different machine, you need to run ``init-db`` again to49create the database in the instance folder.5051.. code-block:: none5253 export FLASK_APP=flaskr54 flask init-db53 $ export FLASK_APP=flaskr54 $ flask init-db5556When Flask detects that it's installed (not in editable mode), it uses57a different directory for the instance folder. You can find it at58``venv/var/flaskr-instance`` instead.
10 unmodified lines
69You can use the following command to output a random secret key:7071.. code-block:: none7273 python -c 'import os; print(os.urandom(16))'73 $ python -c 'import os; print(os.urandom(16))'7475 b'_5#y2L"F4Q8z\n\xec]/'7677Create the ``config.py`` file in the instance folder, which the factory
20 unmodified lines
98first install it in the virtual environment:99100.. code-block:: none101102 pip install waitress102 $ pip install waitress103104You need to tell Waitress about your application, but it doesn't use105``FLASK_APP`` like ``flask run`` does. You need to tell it to import and106call the application factory to get an application object.107108.. code-block:: none109110 waitress-serve --call 'flaskr:create_app'110 $ waitress-serve --call 'flaskr:create_app'111112 Serving on http://0.0.0.0:8080113114See :doc:`/deploying/index` for a list of many different ways to host
7 unmodified lines
modified:docs/tutorial/factory.rst+10 added-10 removed
28 unmodified lines
29directory should be treated as a package.3031.. code-block:: none3233 mkdir flaskr33 $ mkdir flaskr3435.. code-block:: python36 :caption: ``flaskr/__init__.py``37
99 unmodified lines
137For Linux and Mac:138139.. code-block:: none140141 export FLASK_APP=flaskr142 export FLASK_ENV=development143 flask run141 $ export FLASK_APP=flaskr142 $ export FLASK_ENV=development143 $ flask run144145For Windows cmd, use ``set`` instead of ``export``:146147.. code-block:: none148149 set FLASK_APP=flaskr150 set FLASK_ENV=development151 flask run149 > set FLASK_APP=flaskr150 > set FLASK_ENV=development151 > flask run152153For Windows PowerShell, use ``$env:`` instead of ``export``:154155.. code-block:: none156157 $env:FLASK_APP = "flaskr"158 $env:FLASK_ENV = "development"159 flask run157 > $env:FLASK_APP = "flaskr"158 > $env:FLASK_ENV = "development"159 > flask run160161You'll see output similar to this:162163.. code-block:: none
14 unmodified lines
modified:docs/tutorial/install.rst+2 added-2 removed
78 unmodified lines
79Use ``pip`` to install your project in the virtual environment.8081.. code-block:: none8283 pip install -e .83 $ pip install -e .8485This tells pip to find ``setup.py`` in the current directory and install86it in *editable* or *development* mode. Editable mode means that as you87make changes to your local code, you'll only need to re-install if you
2 unmodified lines
90You can observe that the project is now installed with ``pip list``.9192.. code-block:: none9394 pip list94 $ pip list9596 Package Version Location97 -------------- --------- ----------------------------------98 click 6.7
15 unmodified lines
modified:docs/tutorial/layout.rst+2 added-2 removed
3 unmodified lines
4Create a project directory and enter it:56.. code-block:: none78 mkdir flask-tutorial9 cd flask-tutorial8 $ mkdir flask-tutorial9 $ cd flask-tutorial1011Then follow the :doc:`installation instructions </installation>` to set12up a Python virtual environment and install Flask for your project.13
97 unmodified lines
modified:docs/tutorial/tests.rst+5 added-5 removed
26 unmodified lines
27Install them both:2829.. code-block:: none3031 pip install pytest coverage31 $ pip install pytest coverage3233.. _pytest: https://pytest.readthedocs.io/34.. _coverage: https://coverage.readthedocs.io/35
473 unmodified lines
509the test functions you've written.510511.. code-block:: none512513 pytest513 $ pytest514515 ========================= test session starts ==========================516 platform linux -- Python 3.6.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0517 rootdir: /home/user/Projects/flask-tutorial, inifile: setup.cfg
13 unmodified lines
531to run pytest instead of running it directly.532533.. code-block:: none534535 coverage run -m pytest535 $ coverage run -m pytest536537You can either view a simple coverage report in the terminal:538539.. code-block:: none540541 coverage report541 $ coverage report542543 Name Stmts Miss Branch BrPart Cover544 ------------------------------------------------------545 flaskr/__init__.py 21 0 2 0 100%
6 unmodified lines
552An HTML report allows you to see which lines were covered in each file:553554.. code-block:: none555556 coverage html556 $ coverage html557558This generates files in the ``htmlcov`` directory. Open559``htmlcov/index.html`` in your browser to see the report.560
1 unmodified line
modified:docs/cli.rst+9 added-9 removed
193 unmodified lines
194command, instead of ``flask run --port 8000``:195196.. code-block:: none197198 export FLASK_RUN_PORT=8000199 flask run198 $ export FLASK_RUN_PORT=8000199 $ flask run200 * Running on http://127.0.0.1:8000/201202These can be added to the ``.flaskenv`` file just like ``FLASK_APP`` to203control default command options.
6 unmodified lines
210python-dotenv is not installed.211212.. code-block:: none213214 flask run214 $ flask run215 * Tip: There are .env files present. Do "pip install python-dotenv" to use them.216217You can tell Flask not to load dotenv files even when python-dotenv is218installed by setting the ``FLASK_SKIP_DOTENV`` environment variable.
3 unmodified lines
222configure as expected.223224.. code-block:: none225226 export FLASK_SKIP_DOTENV=1227 flask run226 $ export FLASK_SKIP_DOTENV=1227 $ flask run228229230Environment Variables From virtualenv231-------------------------------------
3 unmodified lines
235script. Activating the virtualenv will set the variables.236237Unix Bash, :file:`venv/bin/activate`::238239 export FLASK_APP=hello239 $ export FLASK_APP=hello240241Windows CMD, :file:`venv\\Scripts\\activate.bat`::242243 set FLASK_APP=hello243 > set FLASK_APP=hello244245It is preferred to use dotenv support over this, since :file:`.flaskenv` can be246committed to the repository so that it works automatically wherever the project247is checked out.
19 unmodified lines
267 ...268269::270271 flask create_user admin271 $ flask create_user admin272273This example adds the same command, but as ``user create``, a command in a274group. This is useful if you want to organize multiple related commands. ::275
12 unmodified lines
288 app.cli.add_command(user_cli)289290::291292 flask user create demo292 $ flask user create demo293294See :ref:`testing-cli` for an overview of how to test your custom295commands.296
172 unmodified lines
modified:docs/config.rst+4 added-4 removed
162 unmodified lines
163 and can be used for any other security related needs by extensions or your164 application. It should be a long random string of bytes, although unicode165 is accepted too. For example, copy the output of this to your config::166167 python -c 'import os; print(os.urandom(16))'167 $ python -c 'import os; print(os.urandom(16))'168 b'_5#y2L"F4Q8z\n\xec]/'169170 **Do not reveal the secret key when posting questions or committing code.**171
246 unmodified lines
418 * Restarting with reloader...419420On Windows systems use the `set` builtin instead::421422 >set YOURAPPLICATION_SETTINGS=\path\to\settings.cfg422 > set YOURAPPLICATION_SETTINGS=\path\to\settings.cfg423424The configuration files themselves are actual Python files. Only values425in uppercase are actually stored in the config object later on. So make426sure to use uppercase letters for your config keys.
27 unmodified lines
454 * Restarting with reloader...455456On Windows systems use the `set` builtin instead::457458 >set SECRET_KEY='5f352379324c22463451387a0aec5d2f'459 >set DEBUG=False458 > set SECRET_KEY='5f352379324c22463451387a0aec5d2f'459 > set DEBUG=False460461While this approach is straightforward to use, it is important to remember that462environment variables are strings -- they are not automatically deserialized463into Python types.
195 unmodified lines
modified:docs/installation.rst+17 added-17 removed
79 unmodified lines
80Create a project folder and a :file:`venv` folder within:8182.. code-block:: sh8384 mkdir myproject85 cd myproject86 python3 -m venv venv84 $ mkdir myproject85 $ cd myproject86 $ python3 -m venv venv8788On Windows:8990.. code-block:: bat9192 py -3 -m venv venv92 $ py -3 -m venv venv9394If you needed to install virtualenv because you are on an older version of95Python, use the following command instead:9697.. code-block:: sh9899 virtualenv venv99 $ virtualenv venv100101On Windows:102103.. code-block:: bat104105 \Python27\Scripts\virtualenv.exe venv105 > \Python27\Scripts\virtualenv.exe venv106107.. _install-activate-env:108109Activate the environment
2 unmodified lines
112Before you work on your project, activate the corresponding environment:113114.. code-block:: sh115116 . venv/bin/activate116 $ . venv/bin/activate117118On Windows:119120.. code-block:: bat121122 venv\Scripts\activate122 > venv\Scripts\activate123124Your shell prompt will change to show the name of the activated environment.125126Install Flask
2 unmodified lines
129Within the activated environment, use the following command to install Flask:130131.. code-block:: sh132133 pip install Flask133 $ pip install Flask134135Flask is now installed. Check out the :doc:`/quickstart` or go to the136:doc:`Documentation Overview </index>`.137
4 unmodified lines
142update the code from the master branch:143144.. code-block:: sh145146 pip install -U https://github.com/pallets/flask/archive/master.tar.gz146 $ pip install -U https://github.com/pallets/flask/archive/master.tar.gz147148.. _install-install-virtualenv:149150Install virtualenv
6 unmodified lines
157158.. code-block:: sh159160 # Debian, Ubuntu161 sudo apt-get install python-virtualenv161 $ sudo apt-get install python-virtualenv162163 # CentOS, Fedora164 sudo yum install python-virtualenv164 $ sudo yum install python-virtualenv165166 # Arch167 sudo pacman -S python-virtualenv167 $ sudo pacman -S python-virtualenv168169If you are on Mac OS X or Windows, download `get-pip.py`_, then:170171.. code-block:: sh172173 sudo python2 Downloads/get-pip.py174 sudo python2 -m pip install virtualenv173 $ sudo python2 Downloads/get-pip.py174 $ sudo python2 -m pip install virtualenv175176On Windows, as an administrator:177178.. code-block:: bat179180 \Python27\python.exe Downloads\get-pip.py181 \Python27\python.exe -m pip install virtualenv180 > \Python27\python.exe Downloads\get-pip.py181 > \Python27\python.exe -m pip install virtualenv182183Now you can return above and :ref:`install-create-env`.184185.. _virtualenv: https://virtualenv.pypa.io/
1 unmodified line
modified:docs/quickstart.rst+1 added-1 removed
83 unmodified lines
84 If you have the debugger disabled or trust the users on your network,85 you can make the server publicly available simply by adding86 ``--host=0.0.0.0`` to the command line::8788 flask run --host=0.0.0.088 $ flask run --host=0.0.0.08990 This tells your operating system to listen on all public IPs.9192
759 unmodified lines
modified:docs/testing.rst+1 added-1 removed
16 unmodified lines
1718In this documentation we will use the `pytest`_ package as the base19framework for our tests. You can install it with ``pip``, like so::2021 pip install pytest21 $ pip install pytest2223.. _pytest:24 https://pytest.org25
431 unmodified lines
modified:docs/upgrading.rst+2 added-2 removed
216 unmodified lines
2171. Download the script: `flask-07-upgrade.py218 <https://raw.githubusercontent.com/pallets/flask/0.12.3/scripts/flask-07-upgrade.py>`_2192. Run it in the directory of your application::220221 python flask-07-upgrade.py > patchfile.diff221 $ python flask-07-upgrade.py > patchfile.diff2222233. Review the generated patchfile.2244. Apply the patch::225226 patch -p1 < patchfile.diff226 $ patch -p1 < patchfile.diff2272285. If you were using per-module template folders you need to move some229 templates around. Previously if you had a folder named :file:`templates`230 next to a blueprint named ``admin`` the implicit template path
242 unmodified lines
modified:examples/javascript/README.rst+8 added-8 removed
21 unmodified lines
22-------2324::2526 python3 -m venv venv27 . venv/bin/activate28 pip install -e .26 $ python3 -m venv venv27 $ . venv/bin/activate28 $ pip install -e .293031Run32---3334::3536 export FLASK_APP=js_example37 flask run36 $ export FLASK_APP=js_example37 $ flask run3839Open http://127.0.0.1:5000 in a browser.4041
1 unmodified line
43----4445::4647 pip install -e '.[test]'48 coverage run -m pytest49 coverage report47 $ pip install -e '.[test]'48 $ coverage run -m pytest49 $ coverage report
modified:examples/tutorial/README.rst+25 added-25 removed
12 unmodified lines
13you're reading.** You probably want the latest tagged version, but the14default Git version is the master branch. ::1516 # clone the repository17 git clone https://github.com/pallets/flask18 cd flask17 $ git clone https://github.com/pallets/flask18 $ cd flask19 # checkout the correct version20 git tag # shows the tagged versions21 git checkout latest-tag-found-above22 cd examples/tutorial20 $ git tag # shows the tagged versions21 $ git checkout latest-tag-found-above22 $ cd examples/tutorial2324Create a virtualenv and activate it::2526 python3 -m venv venv27 . venv/bin/activate26 $ python3 -m venv venv27 $ . venv/bin/activate2829Or on Windows cmd::3031 py -3 -m venv venv32 venv\Scripts\activate.bat31 $ py -3 -m venv venv32 $ venv\Scripts\activate.bat3334Install Flaskr::3536 pip install -e .36 $ pip install -e .3738Or if you are using the master branch, install Flask from source before39installing Flaskr::4041 pip install -e ../..42 pip install -e .41 $ pip install -e ../..42 $ pip install -e .434445Run46---4748::4950 export FLASK_APP=flaskr51 export FLASK_ENV=development52 flask init-db53 flask run50 $ export FLASK_APP=flaskr51 $ export FLASK_ENV=development52 $ flask init-db53 $ flask run5455Or on Windows cmd::5657 set FLASK_APP=flaskr58 set FLASK_ENV=development59 flask init-db60 flask run57 > set FLASK_APP=flaskr58 > set FLASK_ENV=development59 > flask init-db60 > flask run6162Open http://127.0.0.1:5000 in a browser.6364
1 unmodified line
66----6768::6970 pip install '.[test]'71 pytest70 $ pip install '.[test]'71 $ pytest7273Run with coverage report::7475 coverage run -m pytest76 coverage report77 coverage html # open htmlcov/index.html in a browser75 $ coverage run -m pytest76 $ coverage report77 $ coverage html # open htmlcov/index.html in a browser