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
Provenance
- Commit
21b0aa6- Tree
6bbe136- Author
Grey Li <withlihui@gmail.com>- Committer
Hsiaoming Yang <me@lepture.com>- Parent
b9b88b0
19 files changed+112 added−112 removed
modified:docs/deploying/fastcgi.rst+1 added-1 removed
47 unmodified lines48 can execute it:49 50 .. sourcecode:: text51 52- # chmod +x /var/www/yourapplication/yourapplication.fcgi52+ $ chmod +x /var/www/yourapplication/yourapplication.fcgi53 54 Configuring Apache55 ------------------56 184 unmodified linesmodified:docs/deploying/mod_wsgi.rst+3 added-3 removed
25 unmodified lines26 follows:27 28 .. sourcecode:: text29 30- # apt-get install libapache2-mod-wsgi30+ $ apt-get install libapache2-mod-wsgi31 32 If you are using a yum based distribution (Fedora, OpenSUSE, etc..) you33 can install it as follows:34 35 .. sourcecode:: text36 37- # yum install mod_wsgi37+ $ yum install mod_wsgi38 39 On FreeBSD install `mod_wsgi` by compiling the `www/mod_wsgi` port or by40 using pkg_add:41 42 .. sourcecode:: text43 44- # pkg install ap22-mod_wsgi244+ $ pkg install ap22-mod_wsgi245 46 If you are using pkgsrc you can install `mod_wsgi` by compiling the47 `www/ap2-wsgi` package.48 169 unmodified linesmodified:docs/deploying/wsgi-standalone.rst+5 added-5 removed
13 unmodified lines14 `Gunicorn`_ 'Green Unicorn' is a WSGI HTTP Server for UNIX. It's a pre-fork15 worker model ported from Ruby's Unicorn project. It supports both `eventlet`_16 and `greenlet`_. Running a Flask application on this server is quite simple::17 18- gunicorn myproject:app18+ $ gunicorn myproject:app19 20 `Gunicorn`_ provides many command-line options -- see ``gunicorn -h``.21 For example, to run a Flask application with 4 worker processes (``-w22 4``) binding to localhost port 4000 (``-b 127.0.0.1:4000``)::23 24- gunicorn -w 4 -b 127.0.0.1:4000 myproject:app24+ $ gunicorn -w 4 -b 127.0.0.1:4000 myproject:app25 26 .. _Gunicorn: http://gunicorn.org/27 .. _eventlet: http://eventlet.net/28 .. _greenlet: https://greenlet.readthedocs.io/en/latest/5 unmodified lines34 which makes it more complicated to setup than gunicorn.35 36 Running `uWSGI HTTP Router`_::37 38- uwsgi --http 127.0.0.1:5000 --module myproject:app38+ $ uwsgi --http 127.0.0.1:5000 --module myproject:app39 40 For a more optimized setup, see :doc:`configuring uWSGI and NGINX <uwsgi>`.41 42 .. _uWSGI: http://uwsgi-docs.readthedocs.io/en/latest/23 unmodified lines66 non-blocking event-driven networking library. Twisted Web comes with a67 standard WSGI container which can be controlled from the command line using68 the ``twistd`` utility::69 70- twistd web --wsgi myproject.app70+ $ twistd web --wsgi myproject.app71 72 This example will run a Flask application called ``app`` from a module named73 ``myproject``.74 1 unmodified line76 as well; see ``twistd -h`` and ``twistd web -h`` for more information. For77 example, to run a Twisted Web server in the foreground, on port 8080, with an78 application from ``myproject``::79 80- twistd -n web --port tcp:8080 --wsgi myproject.app80+ $ twistd -n web --port tcp:8080 --wsgi myproject.app81 82 .. _Twisted: https://twistedmatrix.com/83 .. _Twisted Web: https://twistedmatrix.com/trac/wiki/TwistedWeb84 65 unmodified linesmodified:docs/patterns/appfactories.rst+4 added-4 removed
89 unmodified lines90 ------------------91 92 To run such an application, you can use the :command:`flask` command::93 94- export FLASK_APP=myapp95- flask run94+ $ export FLASK_APP=myapp95+ $ flask run96 97 Flask will automatically detect the factory (``create_app`` or ``make_app``) 98 in ``myapp``. You can also pass arguments to the factory like this::99 100- export FLASK_APP="myapp:create_app('dev')"101- flask run100+ $ export FLASK_APP="myapp:create_app('dev')"101+ $ flask run102 103 Then the ``create_app`` factory in ``myapp`` is called with the string104 ``'dev'`` as the argument. See :doc:`/cli` for more detail.105 12 unmodified linesmodified:docs/patterns/packages.rst+4 added-4 removed
59 unmodified lines60 61 In order to run the application you need to export an environment variable62 that tells Flask where to find the application instance::63 64- export FLASK_APP=yourapplication64+ $ export FLASK_APP=yourapplication65 66 If you are outside of the project directory make sure to provide the exact67 path to your application directory. Similarly you can turn on the68 development features like this::69 70- export FLASK_ENV=development70+ $ export FLASK_ENV=development71 72 In order to install and run the application you need to issue the following73 commands::74 75- pip install -e .76- flask run75+ $ pip install -e .76+ $ flask run77 78 What did we gain from this? Now we can restructure the application a bit79 into multiple modules. The only thing you have to remember is the80 following quick checklist:63 unmodified linesmodified:docs/tutorial/database.rst+1 added-1 removed
202 unmodified lines203 Run the ``init-db`` command:204 205 .. code-block:: none206 207- flask init-db207+ $ flask init-db208 Initialized the database.209 210 There will now be a ``flaskr.sqlite`` file in the ``instance`` folder in211 your project.2 unmodified linesmodified:docs/tutorial/deploy.rst+8 added-8 removed
19 unmodified lines20 is installed first:21 22 .. code-block:: none23 24- pip install wheel24+ $ pip install wheel25 26 Running ``setup.py`` with Python gives you a command line tool to issue27 build-related commands. The ``bdist_wheel`` command will build a wheel28 distribution file.29 30 .. code-block:: none31 32- python setup.py bdist_wheel32+ $ python setup.py bdist_wheel33 34 You can find the file in ``dist/flaskr-1.0.0-py3-none-any.whl``. The35 file name is the name of the project, the version, and some tags about36 the file can install.3 unmodified lines40 file with ``pip``.41 42 .. code-block:: none43 44- pip install flaskr-1.0.0-py3-none-any.whl44+ $ pip install flaskr-1.0.0-py3-none-any.whl45 46 Pip will install your project along with its dependencies.47 48 Since this is a different machine, you need to run ``init-db`` again to49 create the database in the instance folder.50 51 .. code-block:: none52 53- export FLASK_APP=flaskr54- flask init-db53+ $ export FLASK_APP=flaskr54+ $ flask init-db55 56 When Flask detects that it's installed (not in editable mode), it uses57 a different directory for the instance folder. You can find it at58 ``venv/var/flaskr-instance`` instead.10 unmodified lines69 You can use the following command to output a random secret key:70 71 .. code-block:: none72 73- python -c 'import os; print(os.urandom(16))'73+ $ python -c 'import os; print(os.urandom(16))'74 75 b'_5#y2L"F4Q8z\n\xec]/'76 77 Create the ``config.py`` file in the instance folder, which the factory20 unmodified lines98 first install it in the virtual environment:99 100 .. code-block:: none101 102- pip install waitress102+ $ pip install waitress103 104 You 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 and106 call the application factory to get an application object.107 108 .. code-block:: none109 110- waitress-serve --call 'flaskr:create_app'110+ $ waitress-serve --call 'flaskr:create_app'111 112 Serving on http://0.0.0.0:8080113 114 See :doc:`/deploying/index` for a list of many different ways to host7 unmodified linesmodified:docs/tutorial/factory.rst+10 added-10 removed
28 unmodified lines29 directory should be treated as a package.30 31 .. code-block:: none32 33- mkdir flaskr33+ $ mkdir flaskr34 35 .. code-block:: python36 :caption: ``flaskr/__init__.py``37 99 unmodified lines137 For Linux and Mac:138 139 .. code-block:: none140 141- export FLASK_APP=flaskr142- export FLASK_ENV=development143- flask run141+ $ export FLASK_APP=flaskr142+ $ export FLASK_ENV=development143+ $ flask run144 145 For Windows cmd, use ``set`` instead of ``export``:146 147 .. code-block:: none148 149- set FLASK_APP=flaskr150- set FLASK_ENV=development151- flask run149+ > set FLASK_APP=flaskr150+ > set FLASK_ENV=development151+ > flask run152 153 For Windows PowerShell, use ``$env:`` instead of ``export``:154 155 .. code-block:: none156 157- $env:FLASK_APP = "flaskr"158- $env:FLASK_ENV = "development"159- flask run157+ > $env:FLASK_APP = "flaskr"158+ > $env:FLASK_ENV = "development"159+ > flask run160 161 You'll see output similar to this:162 163 .. code-block:: none14 unmodified linesmodified:docs/tutorial/install.rst+2 added-2 removed
78 unmodified lines79 Use ``pip`` to install your project in the virtual environment.80 81 .. code-block:: none82 83- pip install -e .83+ $ pip install -e .84 85 This tells pip to find ``setup.py`` in the current directory and install86 it in *editable* or *development* mode. Editable mode means that as you87 make changes to your local code, you'll only need to re-install if you2 unmodified lines90 You can observe that the project is now installed with ``pip list``.91 92 .. code-block:: none93 94- pip list94+ $ pip list95 96 Package Version Location97 -------------- --------- ----------------------------------98 click 6.715 unmodified linesmodified:docs/tutorial/layout.rst+2 added-2 removed
3 unmodified lines4 Create a project directory and enter it:5 6 .. code-block:: none7 8- mkdir flask-tutorial9- cd flask-tutorial8+ $ mkdir flask-tutorial9+ $ cd flask-tutorial10 11 Then follow the :doc:`installation instructions </installation>` to set12 up a Python virtual environment and install Flask for your project.13 97 unmodified linesmodified:docs/tutorial/tests.rst+5 added-5 removed
26 unmodified lines27 Install them both:28 29 .. code-block:: none30 31- pip install pytest coverage31+ $ pip install pytest coverage32 33 .. _pytest: https://pytest.readthedocs.io/34 .. _coverage: https://coverage.readthedocs.io/35 473 unmodified lines509 the test functions you've written.510 511 .. code-block:: none512 513- pytest513+ $ pytest514 515 ========================= 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.cfg13 unmodified lines531 to run pytest instead of running it directly.532 533 .. code-block:: none534 535- coverage run -m pytest535+ $ coverage run -m pytest536 537 You can either view a simple coverage report in the terminal:538 539 .. code-block:: none540 541- coverage report541+ $ coverage report542 543 Name Stmts Miss Branch BrPart Cover544 ------------------------------------------------------545 flaskr/__init__.py 21 0 2 0 100%6 unmodified lines552 An HTML report allows you to see which lines were covered in each file:553 554 .. code-block:: none555 556- coverage html556+ $ coverage html557 558 This generates files in the ``htmlcov`` directory. Open559 ``htmlcov/index.html`` in your browser to see the report.560 1 unmodified linemodified:docs/cli.rst+9 added-9 removed
193 unmodified lines194 command, instead of ``flask run --port 8000``:195 196 .. code-block:: none197 198- export FLASK_RUN_PORT=8000199- flask run198+ $ export FLASK_RUN_PORT=8000199+ $ flask run200 * Running on http://127.0.0.1:8000/201 202 These can be added to the ``.flaskenv`` file just like ``FLASK_APP`` to203 control default command options.6 unmodified lines210 python-dotenv is not installed.211 212 .. code-block:: none213 214- flask run214+ $ flask run215 * Tip: There are .env files present. Do "pip install python-dotenv" to use them.216 217 You can tell Flask not to load dotenv files even when python-dotenv is218 installed by setting the ``FLASK_SKIP_DOTENV`` environment variable.3 unmodified lines222 configure as expected.223 224 .. code-block:: none225 226- export FLASK_SKIP_DOTENV=1227- flask run226+ $ export FLASK_SKIP_DOTENV=1227+ $ flask run228 229 230 Environment Variables From virtualenv231 -------------------------------------3 unmodified lines235 script. Activating the virtualenv will set the variables.236 237 Unix Bash, :file:`venv/bin/activate`::238 239- export FLASK_APP=hello239+ $ export FLASK_APP=hello240 241 Windows CMD, :file:`venv\\Scripts\\activate.bat`::242 243- set FLASK_APP=hello243+ > set FLASK_APP=hello244 245 It is preferred to use dotenv support over this, since :file:`.flaskenv` can be246 committed to the repository so that it works automatically wherever the project247 is checked out.19 unmodified lines267 ...268 269 ::270 271- flask create_user admin271+ $ flask create_user admin272 273 This example adds the same command, but as ``user create``, a command in a274 group. This is useful if you want to organize multiple related commands. ::275 12 unmodified lines288 app.cli.add_command(user_cli)289 290 ::291 292- flask user create demo292+ $ flask user create demo293 294 See :ref:`testing-cli` for an overview of how to test your custom295 commands.296 172 unmodified linesmodified:docs/config.rst+4 added-4 removed
162 unmodified lines163 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::166 167- python -c 'import os; print(os.urandom(16))'167+ $ python -c 'import os; print(os.urandom(16))'168 b'_5#y2L"F4Q8z\n\xec]/'169 170 **Do not reveal the secret key when posting questions or committing code.**171 246 unmodified lines418 * Restarting with reloader...419 420 On Windows systems use the `set` builtin instead::421 422- >set YOURAPPLICATION_SETTINGS=\path\to\settings.cfg422+ > set YOURAPPLICATION_SETTINGS=\path\to\settings.cfg423 424 The configuration files themselves are actual Python files. Only values425 in uppercase are actually stored in the config object later on. So make426 sure to use uppercase letters for your config keys.27 unmodified lines454 * Restarting with reloader...455 456 On Windows systems use the `set` builtin instead::457 458- >set SECRET_KEY='5f352379324c22463451387a0aec5d2f'459- >set DEBUG=False458+ > set SECRET_KEY='5f352379324c22463451387a0aec5d2f'459+ > set DEBUG=False460 461 While this approach is straightforward to use, it is important to remember that462 environment variables are strings -- they are not automatically deserialized463 into Python types.195 unmodified linesmodified:docs/installation.rst+17 added-17 removed
79 unmodified lines80 Create a project folder and a :file:`venv` folder within:81 82 .. code-block:: sh83 84- mkdir myproject85- cd myproject86- python3 -m venv venv84+ $ mkdir myproject85+ $ cd myproject86+ $ python3 -m venv venv87 88 On Windows:89 90 .. code-block:: bat91 92- py -3 -m venv venv92+ $ py -3 -m venv venv93 94 If you needed to install virtualenv because you are on an older version of95 Python, use the following command instead:96 97 .. code-block:: sh98 99- virtualenv venv99+ $ virtualenv venv100 101 On Windows:102 103 .. code-block:: bat104 105- \Python27\Scripts\virtualenv.exe venv105+ > \Python27\Scripts\virtualenv.exe venv106 107 .. _install-activate-env:108 109 Activate the environment2 unmodified lines112 Before you work on your project, activate the corresponding environment:113 114 .. code-block:: sh115 116- . venv/bin/activate116+ $ . venv/bin/activate117 118 On Windows:119 120 .. code-block:: bat121 122- venv\Scripts\activate122+ > venv\Scripts\activate123 124 Your shell prompt will change to show the name of the activated environment.125 126 Install Flask2 unmodified lines129 Within the activated environment, use the following command to install Flask:130 131 .. code-block:: sh132 133- pip install Flask133+ $ pip install Flask134 135 Flask is now installed. Check out the :doc:`/quickstart` or go to the136 :doc:`Documentation Overview </index>`.137 4 unmodified lines142 update the code from the master branch:143 144 .. code-block:: sh145 146- pip install -U https://github.com/pallets/flask/archive/master.tar.gz146+ $ pip install -U https://github.com/pallets/flask/archive/master.tar.gz147 148 .. _install-install-virtualenv:149 150 Install virtualenv6 unmodified lines157 158 .. code-block:: sh159 160 # Debian, Ubuntu161- sudo apt-get install python-virtualenv161+ $ sudo apt-get install python-virtualenv162 163 # CentOS, Fedora164- sudo yum install python-virtualenv164+ $ sudo yum install python-virtualenv165 166 # Arch167- sudo pacman -S python-virtualenv167+ $ sudo pacman -S python-virtualenv168 169 If you are on Mac OS X or Windows, download `get-pip.py`_, then:170 171 .. code-block:: sh172 173- sudo python2 Downloads/get-pip.py174- sudo python2 -m pip install virtualenv173+ $ sudo python2 Downloads/get-pip.py174+ $ sudo python2 -m pip install virtualenv175 176 On Windows, as an administrator:177 178 .. code-block:: bat179 180- \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 virtualenv182 183 Now you can return above and :ref:`install-create-env`.184 185 .. _virtualenv: https://virtualenv.pypa.io/1 unmodified linemodified:docs/quickstart.rst+1 added-1 removed
83 unmodified lines84 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::87 88- flask run --host=0.0.0.088+ $ flask run --host=0.0.0.089 90 This tells your operating system to listen on all public IPs.91 92 759 unmodified linesmodified:docs/testing.rst+1 added-1 removed
16 unmodified lines17 18 In this documentation we will use the `pytest`_ package as the base19 framework for our tests. You can install it with ``pip``, like so::20 21- pip install pytest21+ $ pip install pytest22 23 .. _pytest:24 https://pytest.org25 431 unmodified linesmodified:docs/upgrading.rst+2 added-2 removed
216 unmodified lines217 1. Download the script: `flask-07-upgrade.py218 <https://raw.githubusercontent.com/pallets/flask/0.12.3/scripts/flask-07-upgrade.py>`_219 2. Run it in the directory of your application::220 221- python flask-07-upgrade.py > patchfile.diff221+ $ python flask-07-upgrade.py > patchfile.diff222 223 3. Review the generated patchfile.224 4. Apply the patch::225 226- patch -p1 < patchfile.diff226+ $ patch -p1 < patchfile.diff227 228 5. 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 path242 unmodified linesmodified:examples/javascript/README.rst+8 added-8 removed
21 unmodified lines22 -------23 24 ::25 26- python3 -m venv venv27- . venv/bin/activate28- pip install -e .26+ $ python3 -m venv venv27+ $ . venv/bin/activate28+ $ pip install -e .29 30 31 Run32 ---33 34 ::35 36- export FLASK_APP=js_example37- flask run36+ $ export FLASK_APP=js_example37+ $ flask run38 39 Open http://127.0.0.1:5000 in a browser.40 41 1 unmodified line43 ----44 45 ::46 47- pip install -e '.[test]'48- coverage run -m pytest49- coverage report47+ $ pip install -e '.[test]'48+ $ coverage run -m pytest49+ $ coverage reportmodified:examples/tutorial/README.rst+25 added-25 removed
12 unmodified lines13 you're reading.** You probably want the latest tagged version, but the14 default Git version is the master branch. ::15 16 # 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/tutorial23 24 Create a virtualenv and activate it::25 26- python3 -m venv venv27- . venv/bin/activate26+ $ python3 -m venv venv27+ $ . venv/bin/activate28 29 Or on Windows cmd::30 31- py -3 -m venv venv32- venv\Scripts\activate.bat31+ $ py -3 -m venv venv32+ $ venv\Scripts\activate.bat33 34 Install Flaskr::35 36- pip install -e .36+ $ pip install -e .37 38 Or if you are using the master branch, install Flask from source before39 installing Flaskr::40 41- pip install -e ../..42- pip install -e .41+ $ pip install -e ../..42+ $ pip install -e .43 44 45 Run46 ---47 48 ::49 50- 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 run54 55 Or on Windows cmd::56 57- 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 run61 62 Open http://127.0.0.1:5000 in a browser.63 64 1 unmodified line66 ----67 68 ::69 70- pip install '.[test]'71- pytest70+ $ pip install '.[test]'71+ $ pytest72 73 Run with coverage report::74 75- 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