Merge pull request #3175 from singingwolfboy/fix-rst-line-too-long

fix RST line too long
This commit is contained in:
David Baumgold 2019-05-06 15:23:35 -04:00 committed by GitHub
commit 819368a52d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 104 additions and 89 deletions

View file

@ -8,10 +8,11 @@ Thread-Locals in Flask
One of the design decisions in Flask was that simple tasks should be simple; One of the design decisions in Flask was that simple tasks should be simple;
they should not take a lot of code and yet they should not limit you. Because they should not take a lot of code and yet they should not limit you. Because
of that, Flask has a few design choices that some people might find surprising or of that, Flask has a few design choices that some people might find
unorthodox. For example, Flask uses thread-local objects internally so that you surprising or unorthodox. For example, Flask uses thread-local objects
dont have to pass objects around from function to function within a request in internally so that you dont have to pass objects around from
order to stay threadsafe. This approach is convenient, but requires a valid function to function within a request in order to stay threadsafe.
This approach is convenient, but requires a valid
request context for dependency injection or when attempting to reuse code which request context for dependency injection or when attempting to reuse code which
uses a value pegged to the request. The Flask project is honest about uses a value pegged to the request. The Flask project is honest about
thread-locals, does not hide them, and calls out in the code and documentation thread-locals, does not hide them, and calls out in the code and documentation

View file

@ -35,7 +35,8 @@ Subclass.
The :class:`~flask.Flask` class has many methods designed for subclassing. You The :class:`~flask.Flask` class has many methods designed for subclassing. You
can quickly add or customize behavior by subclassing :class:`~flask.Flask` (see can quickly add or customize behavior by subclassing :class:`~flask.Flask` (see
the linked method docs) and using that subclass wherever you instantiate an the linked method docs) and using that subclass wherever you instantiate an
application class. This works well with :ref:`app-factories`. See :doc:`/patterns/subclassing` for an example. application class. This works well with :ref:`app-factories`.
See :doc:`/patterns/subclassing` for an example.
Wrap with middleware. Wrap with middleware.
--------------------- ---------------------

View file

@ -258,13 +258,14 @@ Here is an example for a "404 Page Not Found" exception::
Most errorhandlers will simply work as expected; however, there is a caveat Most errorhandlers will simply work as expected; however, there is a caveat
concerning handlers for 404 and 405 exceptions. These errorhandlers are only concerning handlers for 404 and 405 exceptions. These errorhandlers are only
invoked from an appropriate ``raise`` statement or a call to ``abort`` in another invoked from an appropriate ``raise`` statement or a call to ``abort``
of the blueprint's view functions; they are not invoked by, e.g., an invalid URL in another of the blueprint's view functions; they are not invoked by,
access. This is because the blueprint does not "own" a certain URL space, so e.g., an invalid URL access. This is because the blueprint does not
the application instance has no way of knowing which blueprint errorhandler it "own" a certain URL space, so the application instance has no way of
should run if given an invalid URL. If you would like to execute different knowing which blueprint errorhandler it should run if given an invalid URL.
handling strategies for these errors based on URL prefixes, they may be defined If you would like to execute different handling strategies for these errors
at the application level using the ``request`` proxy object:: based on URL prefixes, they may be defined at the application level using
the ``request`` proxy object::
@app.errorhandler(404) @app.errorhandler(404)
@app.errorhandler(405) @app.errorhandler(405)

View file

@ -193,7 +193,7 @@ environment variables. The variables use the pattern
``FLASK_COMMAND_OPTION``. For example, to set the port for the run ``FLASK_COMMAND_OPTION``. For example, to set the port for the run
command, instead of ``flask run --port 8000``: command, instead of ``flask run --port 8000``:
.. code-block:: none .. code-block:: bash
$ export FLASK_RUN_PORT=8000 $ export FLASK_RUN_PORT=8000
$ flask run $ flask run
@ -209,7 +209,7 @@ Disable dotenv
The ``flask`` command will show a message if it detects dotenv files but The ``flask`` command will show a message if it detects dotenv files but
python-dotenv is not installed. python-dotenv is not installed.
.. code-block:: none .. code-block:: bash
$ flask run $ flask run
* Tip: There are .env files present. Do "pip install python-dotenv" to use them. * Tip: There are .env files present. Do "pip install python-dotenv" to use them.
@ -221,7 +221,7 @@ a project runner that loads them already. Keep in mind that the
environment variables must be set before the app loads or it won't environment variables must be set before the app loads or it won't
configure as expected. configure as expected.
.. code-block:: none .. code-block:: bash
$ export FLASK_SKIP_DOTENV=1 $ export FLASK_SKIP_DOTENV=1
$ flask run $ flask run

View file

@ -46,9 +46,9 @@ In Apache for example you can put something like this into the config:
ScriptAlias /app /path/to/the/application.cgi ScriptAlias /app /path/to/the/application.cgi
On shared webhosting, though, you might not have access to your Apache config. On shared webhosting, though, you might not have access to your Apache config.
In this case, a file called ``.htaccess``, sitting in the public directory you want In this case, a file called ``.htaccess``, sitting in the public directory
your app to be available, works too but the ``ScriptAlias`` directive won't you want your app to be available, works too but the ``ScriptAlias`` directive
work in that case: won't work in that case:
.. sourcecode:: apache .. sourcecode:: apache

View file

@ -4,10 +4,10 @@ FastCGI
======= =======
FastCGI is a deployment option on servers like `nginx`_, `lighttpd`_, and FastCGI is a deployment option on servers like `nginx`_, `lighttpd`_, and
`cherokee`_; see :doc:`uwsgi` and :doc:`wsgi-standalone` for other options. To `cherokee`_; see :doc:`uwsgi` and :doc:`wsgi-standalone` for other options.
use your WSGI application with any of them you will need a FastCGI server first. To use your WSGI application with any of them you will need a FastCGI
The most popular one is `flup`_ which we will use for this guide. Make sure to server first. The most popular one is `flup`_ which we will use for
have it installed to follow along. this guide. Make sure to have it installed to follow along.
.. admonition:: Watch Out .. admonition:: Watch Out

View file

@ -52,10 +52,10 @@ reload you can safely ignore them. Just restart the server.
Creating a `.wsgi` file Creating a `.wsgi` file
----------------------- -----------------------
To run your application you need a :file:`yourapplication.wsgi` file. This file To run your application you need a :file:`yourapplication.wsgi` file.
contains the code `mod_wsgi` is executing on startup to get the application This file contains the code `mod_wsgi` is executing on startup
object. The object called `application` in that file is then used as to get the application object. The object called `application`
application. in that file is then used as application.
For most applications the following file should be sufficient:: For most applications the following file should be sufficient::
@ -108,16 +108,17 @@ refuse to run with the above configuration. On a Windows system, eliminate those
.. sourcecode:: apache .. sourcecode:: apache
<VirtualHost *> <VirtualHost *>
ServerName example.com ServerName example.com
WSGIScriptAlias / C:\yourdir\yourapp.wsgi WSGIScriptAlias / C:\yourdir\yourapp.wsgi
<Directory C:\yourdir> <Directory C:\yourdir>
Order deny,allow Order deny,allow
Allow from all Allow from all
</Directory> </Directory>
</VirtualHost> </VirtualHost>
Note: There have been some changes in access control configuration for `Apache 2.4`_. Note: There have been some changes in access control configuration
for `Apache 2.4`_.
.. _Apache 2.4: https://httpd.apache.org/docs/trunk/upgrading.html .. _Apache 2.4: https://httpd.apache.org/docs/trunk/upgrading.html

View file

@ -31,10 +31,11 @@ Given a flask application in myapp.py, use the following command:
$ uwsgi -s /tmp/yourapplication.sock --manage-script-name --mount /yourapplication=myapp:app $ uwsgi -s /tmp/yourapplication.sock --manage-script-name --mount /yourapplication=myapp:app
The ``--manage-script-name`` will move the handling of ``SCRIPT_NAME`` to uwsgi, The ``--manage-script-name`` will move the handling of ``SCRIPT_NAME``
since it is smarter about that. It is used together with the ``--mount`` to uwsgi, since it is smarter about that.
directive which will make requests to ``/yourapplication`` be directed to It is used together with the ``--mount`` directive which will make
``myapp:app``. If your application is accessible at root level, you can use a requests to ``/yourapplication`` be directed to ``myapp:app``.
If your application is accessible at root level, you can use a
single ``/`` instead of ``/yourapplication``. ``myapp`` refers to the name of single ``/`` instead of ``/yourapplication``. ``myapp`` refers to the name of
the file of your flask application (without extension) or the module which the file of your flask application (without extension) or the module which
provides ``app``. ``app`` is the callable inside of your application (usually provides ``app``. ``app`` is the callable inside of your application (usually

View file

@ -50,14 +50,15 @@ And then add this to your Flask app::
import sentry_sdk import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration from sentry_sdk.integrations.flask import FlaskIntegration
sentry_sdk.init('YOUR_DSN_HERE',integrations=[FlaskIntegration()]) sentry_sdk.init('YOUR_DSN_HERE',integrations=[FlaskIntegration()])
The `YOUR_DSN_HERE` value needs to be replaced with the DSN value you get The `YOUR_DSN_HERE` value needs to be replaced with the DSN value you get
from your Sentry installation. from your Sentry installation.
After installation, failures leading to an Internal Server Error are automatically reported to After installation, failures leading to an Internal Server Error
Sentry and from there you can receive error notifications. are automatically reported to Sentry and from there you can
receive error notifications.
Follow-up reads: Follow-up reads:
@ -126,8 +127,9 @@ registered, :class:`~werkzeug.exceptions.HTTPException` subclasses show a
generic message about their code, while other exceptions are converted to a generic message about their code, while other exceptions are converted to a
generic 500 Internal Server Error. generic 500 Internal Server Error.
For example, if an instance of :exc:`ConnectionRefusedError` is raised, and a handler For example, if an instance of :exc:`ConnectionRefusedError` is raised,
is registered for :exc:`ConnectionError` and :exc:`ConnectionRefusedError`, and a handler is registered for :exc:`ConnectionError` and
:exc:`ConnectionRefusedError`,
the more specific :exc:`ConnectionRefusedError` handler is called with the the more specific :exc:`ConnectionRefusedError` handler is called with the
exception instance to generate the response. exception instance to generate the response.
@ -183,7 +185,8 @@ options in order to use your favorite debugger:
* ``debug`` - whether to enable debug mode and catch exceptions * ``debug`` - whether to enable debug mode and catch exceptions
* ``use_debugger`` - whether to use the internal Flask debugger * ``use_debugger`` - whether to use the internal Flask debugger
* ``use_reloader`` - whether to reload and fork the process if modules were changed * ``use_reloader`` - whether to reload and fork the process if modules
were changed
``debug`` must be True (i.e., exceptions must be caught) in order for the other ``debug`` must be True (i.e., exceptions must be caught) in order for the other
two options to have any value. two options to have any value.
@ -198,7 +201,8 @@ config.yaml (change the block as appropriate for your application, of course)::
DEBUG: True DEBUG: True
DEBUG_WITH_APTANA: True DEBUG_WITH_APTANA: True
Then in your application's entry-point (main.py), you could have something like:: Then in your application's entry-point (main.py),
you could have something like::
if __name__ == "__main__": if __name__ == "__main__":
# To allow aptana to receive errors, set use_debugger=False # To allow aptana to receive errors, set use_debugger=False

View file

@ -197,8 +197,8 @@ So here's what these lines of code do:
instantiated without requiring an app object. This method supports the instantiated without requiring an app object. This method supports the
factory pattern for creating applications. The ``init_app`` will set the factory pattern for creating applications. The ``init_app`` will set the
configuration for the database, defaulting to an in memory database if configuration for the database, defaulting to an in memory database if
no configuration is supplied. In addition, the ``init_app`` method attaches no configuration is supplied. In addition, the ``init_app`` method
the ``teardown`` handler. attaches the ``teardown`` handler.
3. Next, we define a ``connect`` method that opens a database connection. 3. Next, we define a ``connect`` method that opens a database connection.
4. Finally, we add a ``connection`` property that on first access opens 4. Finally, we add a ``connection`` property that on first access opens
the database connection and stores it on the context. This is also the database connection and stores it on the context. This is also
@ -312,8 +312,8 @@ extension to be approved you have to follow these guidelines:
or ``python setup.py test``. For test suites invoked with ``make or ``python setup.py test``. For test suites invoked with ``make
test`` the extension has to ensure that all dependencies for the test test`` the extension has to ensure that all dependencies for the test
are installed automatically. If tests are invoked with ``python setup.py are installed automatically. If tests are invoked with ``python setup.py
test``, test dependencies can be specified in the :file:`setup.py` file. The test``, test dependencies can be specified in the :file:`setup.py` file.
test suite also has to be part of the distribution. The test suite also has to be part of the distribution.
3. APIs of approved extensions will be checked for the following 3. APIs of approved extensions will be checked for the following
characteristics: characteristics:

View file

@ -28,10 +28,11 @@ Configuration and Conventions
----------------------------- -----------------------------
Flask has many configuration values, with sensible defaults, and a few Flask has many configuration values, with sensible defaults, and a few
conventions when getting started. By convention, templates and static files are conventions when getting started. By convention, templates and static
stored in subdirectories within the application's Python source tree, with the files are stored in subdirectories within the application's Python
names :file:`templates` and :file:`static` respectively. While this can be changed, you source tree, with the names :file:`templates` and :file:`static`
usually don't have to, especially when getting started. respectively. While this can be changed, you usually don't have to,
especially when getting started.
Growing with Flask Growing with Flask
------------------ ------------------

View file

@ -16,8 +16,8 @@ However, barely any websites on the Internet are actual XHTML (which is
HTML processed using XML rules). There are a couple of major reasons HTML processed using XML rules). There are a couple of major reasons
why this is the case. One of them is Internet Explorer's lack of proper why this is the case. One of them is Internet Explorer's lack of proper
XHTML support. The XHTML spec states that XHTML must be served with the MIME XHTML support. The XHTML spec states that XHTML must be served with the MIME
type :mimetype:`application/xhtml+xml`, but Internet Explorer refuses to read files type :mimetype:`application/xhtml+xml`, but Internet Explorer refuses
with that MIME type. to read files with that MIME type.
While it is relatively easy to configure Web servers to serve XHTML properly, While it is relatively easy to configure Web servers to serve XHTML properly,
few people do. This is likely because properly using XHTML can be quite few people do. This is likely because properly using XHTML can be quite
painful. painful.

View file

@ -93,9 +93,9 @@ should see your hello world greeting.
What to do if the Server does not Start What to do if the Server does not Start
--------------------------------------- ---------------------------------------
In case the :command:`python -m flask` fails or :command:`flask` does not exist, In case the :command:`python -m flask` fails or :command:`flask`
there are multiple reasons this might be the case. First of all you need does not exist, there are multiple reasons this might be the case.
to look at the error message. First of all you need to look at the error message.
Old Version of Flask Old Version of Flask
```````````````````` ````````````````````
@ -560,9 +560,9 @@ filesystem. You can access those files by looking at the
:attr:`~flask.request.files` attribute on the request object. Each :attr:`~flask.request.files` attribute on the request object. Each
uploaded file is stored in that dictionary. It behaves just like a uploaded file is stored in that dictionary. It behaves just like a
standard Python :class:`file` object, but it also has a standard Python :class:`file` object, but it also has a
:meth:`~werkzeug.datastructures.FileStorage.save` method that allows you to store that :meth:`~werkzeug.datastructures.FileStorage.save` method that
file on the filesystem of the server. Here is a simple example showing how allows you to store that file on the filesystem of the server.
that works:: Here is a simple example showing how that works::
from flask import request from flask import request
@ -575,10 +575,11 @@ that works::
If you want to know how the file was named on the client before it was If you want to know how the file was named on the client before it was
uploaded to your application, you can access the uploaded to your application, you can access the
:attr:`~werkzeug.datastructures.FileStorage.filename` attribute. However please keep in :attr:`~werkzeug.datastructures.FileStorage.filename` attribute.
mind that this value can be forged so never ever trust that value. If you However please keep in mind that this value can be forged
want to use the filename of the client to store the file on the server, so never ever trust that value. If you want to use the filename
pass it through the :func:`~werkzeug.utils.secure_filename` function that of the client to store the file on the server, pass it through the
:func:`~werkzeug.utils.secure_filename` function that
Werkzeug provides for you:: Werkzeug provides for you::
from flask import request from flask import request
@ -681,8 +682,9 @@ About Responses
The return value from a view function is automatically converted into a The return value from a view function is automatically converted into a
response object for you. If the return value is a string it's converted response object for you. If the return value is a string it's converted
into a response object with the string as response body, a ``200 OK`` into a response object with the string as response body, a ``200 OK``
status code and a :mimetype:`text/html` mimetype. The logic that Flask applies to status code and a :mimetype:`text/html` mimetype.
converting return values into response objects is as follows: The logic that Flask applies to converting return values into
response objects is as follows:
1. If a response object of the correct type is returned it's directly 1. If a response object of the correct type is returned it's directly
returned from the view. returned from the view.
@ -806,12 +808,12 @@ Logging
.. versionadded:: 0.3 .. versionadded:: 0.3
Sometimes you might be in a situation where you deal with data that Sometimes you might be in a situation where you deal with data that
should be correct, but actually is not. For example you may have some client-side should be correct, but actually is not. For example you may have
code that sends an HTTP request to the server but it's obviously some client-side code that sends an HTTP request to the server
malformed. This might be caused by a user tampering with the data, or the but it's obviously malformed. This might be caused by a user tampering
client code failing. Most of the time it's okay to reply with ``400 Bad with the data, or the client code failing. Most of the time it's okay
Request`` in that situation, but sometimes that won't do and the code has to reply with ``400 Bad Request`` in that situation, but sometimes
to continue working. that won't do and the code has to continue working.
You may still want to log that something fishy happened. This is where You may still want to log that something fishy happened. This is where
loggers come in handy. As of Flask 0.3 a logger is preconfigured for you loggers come in handy. As of Flask 0.3 a logger is preconfigured for you

View file

@ -73,9 +73,9 @@ this does is disable error catching during request handling, so that
you get better error reports when performing test requests against the you get better error reports when performing test requests against the
application. application.
Because SQLite3 is filesystem-based, we can easily use the :mod:`tempfile` module Because SQLite3 is filesystem-based, we can easily use the
to create a temporary database and initialize it. The :mod:`tempfile` module to create a temporary database and initialize it.
:func:`~tempfile.mkstemp` function does two things for us: it returns a The :func:`~tempfile.mkstemp` function does two things for us: it returns a
low-level file handle and a random file name, the latter we use as low-level file handle and a random file name, the latter we use as
database name. We just have to keep the `db_fd` around so that we can use database name. We just have to keep the `db_fd` around so that we can use
the :func:`os.close` function to close the file. the :func:`os.close` function to close the file.
@ -93,9 +93,9 @@ If we now run the test suite, we should see the following output::
=========== no tests ran in 0.07 seconds ============ =========== no tests ran in 0.07 seconds ============
Even though it did not run any actual tests, we already know that our ``flaskr`` Even though it did not run any actual tests, we already know that our
application is syntactically valid, otherwise the import would have died ``flaskr`` application is syntactically valid, otherwise the import
with an exception. would have died with an exception.
.. _pytest fixture: .. _pytest fixture:
https://docs.pytest.org/en/latest/fixture.html https://docs.pytest.org/en/latest/fixture.html
@ -117,11 +117,13 @@ test function to :file:`test_flaskr.py`, like this::
Notice that our test functions begin with the word `test`; this allows Notice that our test functions begin with the word `test`; this allows
`pytest`_ to automatically identify the function as a test to run. `pytest`_ to automatically identify the function as a test to run.
By using ``client.get`` we can send an HTTP ``GET`` request to the application with By using ``client.get`` we can send an HTTP ``GET`` request to the
the given path. The return value will be a :class:`~flask.Flask.response_class` object. application with the given path. The return value will be a
We can now use the :attr:`~werkzeug.wrappers.BaseResponse.data` attribute to inspect :class:`~flask.Flask.response_class` object. We can now use the
the return value (as string) from the application. In this case, we ensure that :attr:`~werkzeug.wrappers.BaseResponse.data` attribute to inspect
``'No entries here so far'`` is part of the output. the return value (as string) from the application.
In this case, we ensure that ``'No entries here so far'``
is part of the output.
Run it again and you should see one passing test:: Run it again and you should see one passing test::
@ -333,7 +335,8 @@ happen. With Flask 0.4 this is possible by using the
If you were to use just the :meth:`~flask.Flask.test_client` without If you were to use just the :meth:`~flask.Flask.test_client` without
the ``with`` block, the ``assert`` would fail with an error because `request` the ``with`` block, the ``assert`` would fail with an error because `request`
is no longer available (because you are trying to use it outside of the actual request). is no longer available (because you are trying to use it
outside of the actual request).
Accessing and Modifying Sessions Accessing and Modifying Sessions

View file

@ -68,9 +68,9 @@ to the release we decided to push out a 0.11 release first with some
changes removed to make the transition easier. If you have been tracking changes removed to make the transition easier. If you have been tracking
the master branch which was 1.0 you might see some unexpected changes. the master branch which was 1.0 you might see some unexpected changes.
In case you did track the master branch you will notice that :command:`flask --app` In case you did track the master branch you will notice that
is removed now. You need to use the environment variable to specify an :command:`flask --app` is removed now.
application. You need to use the environment variable to specify an application.
Debugging Debugging
````````` `````````