Skip to content
Myr

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

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

fix RST line too long

authored by David Baumgold · committed by GitHub · parents 5e378b4, 6606a4a · Browse files · 15 files+104 added−89 removed
This commit

State

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

Diff stats

15 files+104 added−89 removed

  • other:+104 added−89 removed

15 files+104 added−89 removed

modified:docs/deploying/cgi.rst+3 added-3 removed
44 unmodified lines
4546 ScriptAlias /app /path/to/the/application.cgi4748On shared webhosting, though, you might not have access to your Apache config.49In this case, a file called ``.htaccess``, sitting in the public directory you want50your app to be available, works too but the ``ScriptAlias`` directive won't51work in that case:49In this case, a file called ``.htaccess``, sitting in the public directory50you want your app to be available, works too but the ``ScriptAlias`` directive51won't work in that case:5253.. sourcecode:: apache5455 RewriteEngine On
6 unmodified lines
modified:docs/deploying/fastcgi.rst+4 added-4 removed
2 unmodified lines
3FastCGI4=======56FastCGI is a deployment option on servers like `nginx`_, `lighttpd`_, and7`cherokee`_; see :doc:`uwsgi` and :doc:`wsgi-standalone` for other options. To8use your WSGI application with any of them you will need a FastCGI server first.9The most popular one is `flup`_ which we will use for this guide. Make sure to10have it installed to follow along.7`cherokee`_; see :doc:`uwsgi` and :doc:`wsgi-standalone` for other options.8To use your WSGI application with any of them you will need a FastCGI9server first. The most popular one is `flup`_ which we will use for10this guide. Make sure to have it installed to follow along.1112.. admonition:: Watch Out1314 Please make sure in advance that any ``app.run()`` calls you might
226 unmodified lines
modified:docs/deploying/mod_wsgi.rst+14 added-13 removed
50 unmodified lines
5152Creating a `.wsgi` file53-----------------------5455To run your application you need a :file:`yourapplication.wsgi` file. This file56contains the code `mod_wsgi` is executing on startup to get the application57object. The object called `application` in that file is then used as58application.55To run your application you need a :file:`yourapplication.wsgi` file.56This file contains the code `mod_wsgi` is executing on startup57to get the application object. The object called `application`58in that file is then used as application.5960For most applications the following file should be sufficient::6162 from yourapplication import app as application
44 unmodified lines
107refuse to run with the above configuration. On a Windows system, eliminate those lines:108109.. sourcecode:: apache110111 <VirtualHost *>112 ServerName example.com113 WSGIScriptAlias / C:\yourdir\yourapp.wsgi114 <Directory C:\yourdir>115 Order deny,allow116 Allow from all117 </Directory>118 </VirtualHost>111 <VirtualHost *>112 ServerName example.com113 WSGIScriptAlias / C:\yourdir\yourapp.wsgi114 <Directory C:\yourdir>115 Order deny,allow116 Allow from all117 </Directory>118 </VirtualHost>119120Note: There have been some changes in access control configuration for `Apache 2.4`_.120Note: There have been some changes in access control configuration121for `Apache 2.4`_.122123.. _Apache 2.4: https://httpd.apache.org/docs/trunk/upgrading.html124125Most notably, the syntax for directory permissions has changed from httpd 2.2
98 unmodified lines
modified:docs/deploying/uwsgi.rst+5 added-4 removed
29 unmodified lines
30.. sourcecode:: text3132 $ uwsgi -s /tmp/yourapplication.sock --manage-script-name --mount /yourapplication=myapp:app3334The ``--manage-script-name`` will move the handling of ``SCRIPT_NAME`` to uwsgi,35since it is smarter about that. It is used together with the ``--mount``36directive which will make requests to ``/yourapplication`` be directed to37``myapp:app``. If your application is accessible at root level, you can use a34The ``--manage-script-name`` will move the handling of ``SCRIPT_NAME``35to uwsgi, since it is smarter about that.36It is used together with the ``--mount`` directive which will make37requests to ``/yourapplication`` be directed to ``myapp:app``.38If your application is accessible at root level, you can use a39single ``/`` instead of ``/yourapplication``. ``myapp`` refers to the name of40the file of your flask application (without extension) or the module which41provides ``app``. ``app`` is the callable inside of your application (usually42the line reads ``app = Flask(__name__)``.
31 unmodified lines
modified:docs/advanced_foreword.rst+5 added-4 removed
6 unmodified lines
7----------------------89One of the design decisions in Flask was that simple tasks should be simple;10they should not take a lot of code and yet they should not limit you. Because11of that, Flask has a few design choices that some people might find surprising or12unorthodox. For example, Flask uses thread-local objects internally so that you13don’t have to pass objects around from function to function within a request in14order to stay threadsafe. This approach is convenient, but requires a valid11of that, Flask has a few design choices that some people might find12surprising or unorthodox. For example, Flask uses thread-local objects13internally so that you don’t have to pass objects around from14function to function within a request in order to stay threadsafe.15This approach is convenient, but requires a valid16request context for dependency injection or when attempting to reuse code which17uses a value pegged to the request. The Flask project is honest about18thread-locals, does not hide them, and calls out in the code and documentation19where they are used.
29 unmodified lines
modified:docs/becomingbig.rst+2 added-1 removed
33 unmodified lines
3435The :class:`~flask.Flask` class has many methods designed for subclassing. You36can quickly add or customize behavior by subclassing :class:`~flask.Flask` (see37the linked method docs) and using that subclass wherever you instantiate an38application class. This works well with :ref:`app-factories`. See :doc:`/patterns/subclassing` for an example.38application class. This works well with :ref:`app-factories`.39See :doc:`/patterns/subclassing` for an example.4041Wrap with middleware.42---------------------43
59 unmodified lines
modified:docs/blueprints.rst+8 added-7 removed
256 unmodified lines
257 return render_template('pages/404.html')258259Most errorhandlers will simply work as expected; however, there is a caveat260concerning handlers for 404 and 405 exceptions. These errorhandlers are only261invoked from an appropriate ``raise`` statement or a call to ``abort`` in another262of the blueprint's view functions; they are not invoked by, e.g., an invalid URL263access. This is because the blueprint does not "own" a certain URL space, so264the application instance has no way of knowing which blueprint errorhandler it265should run if given an invalid URL. If you would like to execute different266handling strategies for these errors based on URL prefixes, they may be defined267at the application level using the ``request`` proxy object::261invoked from an appropriate ``raise`` statement or a call to ``abort``262in another of the blueprint's view functions; they are not invoked by,263e.g., an invalid URL access. This is because the blueprint does not264"own" a certain URL space, so the application instance has no way of265knowing which blueprint errorhandler it should run if given an invalid URL.266If you would like to execute different handling strategies for these errors267based on URL prefixes, they may be defined at the application level using268the ``request`` proxy object::269270 @app.errorhandler(404)271 @app.errorhandler(405)272 def _handle_api_error(ex):
6 unmodified lines
modified:docs/cli.rst+3 added-3 removed
191 unmodified lines
192environment variables. The variables use the pattern193``FLASK_COMMAND_OPTION``. For example, to set the port for the run194command, instead of ``flask run --port 8000``:195196.. code-block:: none196.. code-block:: bash197198 $ export FLASK_RUN_PORT=8000199 $ flask run200 * Running on http://127.0.0.1:8000/
7 unmodified lines
208209The ``flask`` command will show a message if it detects dotenv files but210python-dotenv is not installed.211212.. code-block:: none212.. code-block:: bash213214 $ flask run215 * Tip: There are .env files present. Do "pip install python-dotenv" to use them.216
3 unmodified lines
220a project runner that loads them already. Keep in mind that the221environment variables must be set before the app loads or it won't222configure as expected.223224.. code-block:: none224.. code-block:: bash225226 $ export FLASK_SKIP_DOTENV=1227 $ flask run228
240 unmodified lines
modified:docs/errorhandling.rst+11 added-7 removed
48 unmodified lines
49And then add this to your Flask app::5051 import sentry_sdk52 from sentry_sdk.integrations.flask import FlaskIntegration53 5354 sentry_sdk.init('YOUR_DSN_HERE',integrations=[FlaskIntegration()])5556The `YOUR_DSN_HERE` value needs to be replaced with the DSN value you get57from your Sentry installation.5859After installation, failures leading to an Internal Server Error are automatically reported to 60Sentry and from there you can receive error notifications.59After installation, failures leading to an Internal Server Error60are automatically reported to Sentry and from there you can61receive error notifications.6263Follow-up reads:6465* Sentry also supports catching errors from your worker queue (RQ, Celery) in a
60 unmodified lines
126registered, :class:`~werkzeug.exceptions.HTTPException` subclasses show a127generic message about their code, while other exceptions are converted to a128generic 500 Internal Server Error.129129For example, if an instance of :exc:`ConnectionRefusedError` is raised, and a handler130is registered for :exc:`ConnectionError` and :exc:`ConnectionRefusedError`,130For example, if an instance of :exc:`ConnectionRefusedError` is raised,131and a handler is registered for :exc:`ConnectionError` and132:exc:`ConnectionRefusedError`,133the more specific :exc:`ConnectionRefusedError` handler is called with the134exception instance to generate the response.135136Handlers registered on the blueprint take precedence over those registered
47 unmodified lines
184options in order to use your favorite debugger:185186* ``debug`` - whether to enable debug mode and catch exceptions187* ``use_debugger`` - whether to use the internal Flask debugger186* ``use_reloader`` - whether to reload and fork the process if modules were changed188* ``use_reloader`` - whether to reload and fork the process if modules189 were changed190191``debug`` must be True (i.e., exceptions must be caught) in order for the other192two options to have any value.193
6 unmodified lines
200 FLASK:201 DEBUG: True202 DEBUG_WITH_APTANA: True203201Then in your application's entry-point (main.py), you could have something like::204Then in your application's entry-point (main.py),205you could have something like::206207 if __name__ == "__main__":208 # To allow aptana to receive errors, set use_debugger=False209 app = create_app(config="config.yaml")
4 unmodified lines
modified:docs/extensiondev.rst+4 added-4 removed
195 unmodified lines
1962. The ``init_app`` method exists so that the ``SQLite3`` object can be197 instantiated without requiring an app object. This method supports the198 factory pattern for creating applications. The ``init_app`` will set the199 configuration for the database, defaulting to an in memory database if200 no configuration is supplied. In addition, the ``init_app`` method attaches201 the ``teardown`` handler.200 no configuration is supplied. In addition, the ``init_app`` method201 attaches the ``teardown`` handler.2023. Next, we define a ``connect`` method that opens a database connection.2034. Finally, we add a ``connection`` property that on first access opens204 the database connection and stores it on the context. This is also205 the recommended way to handling resources: fetch resources lazily the
105 unmodified lines
3112. It must ship a testing suite that can either be invoked with ``make test``312 or ``python setup.py test``. For test suites invoked with ``make313 test`` the extension has to ensure that all dependencies for the test314 are installed automatically. If tests are invoked with ``python setup.py315 test``, test dependencies can be specified in the :file:`setup.py` file. The316 test suite also has to be part of the distribution.315 test``, test dependencies can be specified in the :file:`setup.py` file.316 The test suite also has to be part of the distribution.3173. APIs of approved extensions will be checked for the following318 characteristics:319320 - an approved extension has to support multiple applications
25 unmodified lines
modified:docs/foreword.rst+5 added-4 removed
26 unmodified lines
27Configuration and Conventions28-----------------------------2930Flask has many configuration values, with sensible defaults, and a few31conventions when getting started. By convention, templates and static files are32stored in subdirectories within the application's Python source tree, with the33names :file:`templates` and :file:`static` respectively. While this can be changed, you34usually don't have to, especially when getting started.31conventions when getting started. By convention, templates and static32files are stored in subdirectories within the application's Python33source tree, with the names :file:`templates` and :file:`static`34respectively. While this can be changed, you usually don't have to,35especially when getting started.3637Growing with Flask38------------------39
19 unmodified lines
modified:docs/htmlfaq.rst+2 added-2 removed
14 unmodified lines
15However, barely any websites on the Internet are actual XHTML (which is16HTML processed using XML rules). There are a couple of major reasons17why this is the case. One of them is Internet Explorer's lack of proper18XHTML support. The XHTML spec states that XHTML must be served with the MIME19type :mimetype:`application/xhtml+xml`, but Internet Explorer refuses to read files20with that MIME type.19type :mimetype:`application/xhtml+xml`, but Internet Explorer refuses20to read files with that MIME type.21While it is relatively easy to configure Web servers to serve XHTML properly,22few people do. This is likely because properly using XHTML can be quite23painful.24
183 unmodified lines
modified:docs/quickstart.rst+20 added-18 removed
91 unmodified lines
9293What to do if the Server does not Start94---------------------------------------9596In case the :command:`python -m flask` fails or :command:`flask` does not exist,97there are multiple reasons this might be the case. First of all you need98to look at the error message.96In case the :command:`python -m flask` fails or :command:`flask`97does not exist, there are multiple reasons this might be the case.98First of all you need to look at the error message.99100Old Version of Flask101````````````````````102
456 unmodified lines
559filesystem. You can access those files by looking at the560:attr:`~flask.request.files` attribute on the request object. Each561uploaded file is stored in that dictionary. It behaves just like a562standard Python :class:`file` object, but it also has a563:meth:`~werkzeug.datastructures.FileStorage.save` method that allows you to store that564file on the filesystem of the server. Here is a simple example showing how565that works::563:meth:`~werkzeug.datastructures.FileStorage.save` method that564allows you to store that file on the filesystem of the server.565Here is a simple example showing how that works::566567 from flask import request568569 @app.route('/upload', methods=['GET', 'POST'])
4 unmodified lines
574 ...575576If you want to know how the file was named on the client before it was577uploaded to your application, you can access the578:attr:`~werkzeug.datastructures.FileStorage.filename` attribute. However please keep in579mind that this value can be forged so never ever trust that value. If you580want to use the filename of the client to store the file on the server,581pass it through the :func:`~werkzeug.utils.secure_filename` function that578:attr:`~werkzeug.datastructures.FileStorage.filename` attribute.579However please keep in mind that this value can be forged580so never ever trust that value. If you want to use the filename581of the client to store the file on the server, pass it through the582:func:`~werkzeug.utils.secure_filename` function that583Werkzeug provides for you::584585 from flask import request586 from werkzeug.utils import secure_filename
94 unmodified lines
681682The return value from a view function is automatically converted into a683response object for you. If the return value is a string it's converted684into a response object with the string as response body, a ``200 OK``684status code and a :mimetype:`text/html` mimetype. The logic that Flask applies to685converting return values into response objects is as follows:685status code and a :mimetype:`text/html` mimetype.686The logic that Flask applies to converting return values into687response objects is as follows:6886891. If a response object of the correct type is returned it's directly690 returned from the view.6912. If it's a string, a response object is created with that data and the
115 unmodified lines
807808.. versionadded:: 0.3809810Sometimes you might be in a situation where you deal with data that809should be correct, but actually is not. For example you may have some client-side810code that sends an HTTP request to the server but it's obviously811malformed. This might be caused by a user tampering with the data, or the812client code failing. Most of the time it's okay to reply with ``400 Bad813Request`` in that situation, but sometimes that won't do and the code has814to continue working.811should be correct, but actually is not. For example you may have812some client-side code that sends an HTTP request to the server813but it's obviously malformed. This might be caused by a user tampering814with the data, or the client code failing. Most of the time it's okay815to reply with ``400 Bad Request`` in that situation, but sometimes816that won't do and the code has to continue working.817818You may still want to log that something fishy happened. This is where819loggers come in handy. As of Flask 0.3 a logger is preconfigured for you820to use.
38 unmodified lines
modified:docs/testing.rst+15 added-12 removed
71 unmodified lines
72this does is disable error catching during request handling, so that73you get better error reports when performing test requests against the74application.7576Because SQLite3 is filesystem-based, we can easily use the :mod:`tempfile` module77to create a temporary database and initialize it. The78:func:`~tempfile.mkstemp` function does two things for us: it returns a76Because SQLite3 is filesystem-based, we can easily use the77:mod:`tempfile` module to create a temporary database and initialize it.78The :func:`~tempfile.mkstemp` function does two things for us: it returns a79low-level file handle and a random file name, the latter we use as80database name. We just have to keep the `db_fd` around so that we can use81the :func:`os.close` function to close the file.82
9 unmodified lines
92 collected 0 items9394 =========== no tests ran in 0.07 seconds ============9596Even though it did not run any actual tests, we already know that our ``flaskr``97application is syntactically valid, otherwise the import would have died98with an exception.96Even though it did not run any actual tests, we already know that our97``flaskr`` application is syntactically valid, otherwise the import98would have died with an exception.99100.. _pytest fixture:101 https://docs.pytest.org/en/latest/fixture.html102
13 unmodified lines
116117Notice that our test functions begin with the word `test`; this allows118`pytest`_ to automatically identify the function as a test to run.119120By using ``client.get`` we can send an HTTP ``GET`` request to the application with121the given path. The return value will be a :class:`~flask.Flask.response_class` object.122We can now use the :attr:`~werkzeug.wrappers.BaseResponse.data` attribute to inspect123the return value (as string) from the application. In this case, we ensure that124``'No entries here so far'`` is part of the output.120By using ``client.get`` we can send an HTTP ``GET`` request to the121application with the given path. The return value will be a122:class:`~flask.Flask.response_class` object. We can now use the123:attr:`~werkzeug.wrappers.BaseResponse.data` attribute to inspect124the return value (as string) from the application.125In this case, we ensure that ``'No entries here so far'``126is part of the output.127128Run it again and you should see one passing test::129130 $ pytest -v
203 unmodified lines
334 assert request.args['tequila'] == '42'335336If you were to use just the :meth:`~flask.Flask.test_client` without337the ``with`` block, the ``assert`` would fail with an error because `request`336is no longer available (because you are trying to use it outside of the actual request).338is no longer available (because you are trying to use it339outside of the actual request).340341342Accessing and Modifying Sessions343--------------------------------
116 unmodified lines
modified:docs/upgrading.rst+3 added-3 removed
66 unmodified lines
67to the release we decided to push out a 0.11 release first with some68changes removed to make the transition easier. If you have been tracking69the master branch which was 1.0 you might see some unexpected changes.7071In case you did track the master branch you will notice that :command:`flask --app`72is removed now. You need to use the environment variable to specify an73application.71In case you did track the master branch you will notice that72:command:`flask --app` is removed now.73You need to use the environment variable to specify an application.7475Debugging76`````````77
395 unmodified lines