Merge branch '1.0.x' into 1.1.x
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parents 908a364, 06507ed · Browse files · 9 files·+71 added−71 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+71 added−71 removed
- other:+71 added−71 removed
Provenance
- Commit
746d918- Tree
84da0be- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
908a364- Parent 2
06507ed
9 files changed+71 added−71 removed
modified:docs/patterns/appdispatch.rst+2 added-2 removed
60 unmodified lines61 62 For example you could have your main application run on ``/`` and your63 backend interface on ``/backend``::64 65- from werkzeug.wsgi import DispatcherMiddleware65+ from werkzeug.middleware.dispatcher import DispatcherMiddleware66 from frontend_app import application as frontend67 from backend_app import application as backend68 69 application = DispatcherMiddleware(frontend, {70- '/backend': backend70+ '/backend': backend71 })72 73 74 Dispatch by Subdomain114 unmodified linesmodified:docs/patterns/fileuploads.rst+1 added-1 removed
119 unmodified lines120 Alternatively you can register `uploaded_file` as `build_only` rule and121 use the :class:`~werkzeug.wsgi.SharedDataMiddleware`. This also works with122 older versions of Flask::123 124- from werkzeug import SharedDataMiddleware124+ from werkzeug.middleware.shared_data import SharedDataMiddleware125 app.add_url_rule('/uploads/<filename>', 'uploaded_file',126 build_only=True)127 app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {128 '/uploads': app.config['UPLOAD_FOLDER']62 unmodified linesmodified:docs/patterns/index.rst+9 added-8 removed
1 unmodified line2 3 Patterns for Flask4 ==================5 6-Certain things are common enough that the chances are high you will find7-them in most web applications. For example quite a lot of applications8-are using relational databases and user authentication. In that case,9-chances are they will open a database connection at the beginning of the10-request and get the information of the currently logged in user. At the11-end of the request, the database connection is closed again.6+Certain features and interactions are common enough that you will find7+them in most web applications. For example, many applications use a8+relational database and user authentication. They will open a database9+connection at the beginning of the request and get the information for10+the logged in user. At the end of the request, the database connection11+is closed.12 13-There are more user contributed snippets and patterns in the `Flask14-Snippet Archives <http://flask.pocoo.org/snippets/>`_.13+These types of patterns may be a bit outside the scope of Flask itself,14+but Flask makes it easy to implement them. Some common patterns are15+collected in the following pages.16 17 .. toctree::18 :maxdepth: 219 27 unmodified linesmodified:docs/patterns/lazyloading.rst+1 added-1 removed
56 unmodified lines57 loaded upfront. The trick is to actually load the view function as needed.58 This can be accomplished with a helper class that behaves just like a59 function but internally imports the real function on first use::60 61- from werkzeug import import_string, cached_property61+ from werkzeug.utils import import_string, cached_property62 63 class LazyView(object):64 65 def __init__(self, import_name):44 unmodified linesmodified:docs/appcontext.rst+1 added-1 removed
142 unmodified lines143 If you're writing an extension, :data:`g` should be reserved for user144 code. You may store internal data on the context itself, but be sure to145 use a sufficiently unique name. The current context is accessed with146 :data:`_app_ctx_stack.top <_app_ctx_stack>`. For more information see147-:doc:`extensiondev`.147+:doc:`/extensiondev`.148 149 150 Events and Signals151 ------------------8 unmodified linesmodified:docs/becomingbig.rst+8 added-8 removed
19 unmodified lines20 Hook. Extend.21 -------------22 23 The :ref:`api` docs are full of available overrides, hook points, and24-:ref:`signals`. You can provide custom classes for things like the request and25-response objects. Dig deeper on the APIs you use, and look for the26-customizations which are available out of the box in a Flask release. Look for27-ways in which your project can be refactored into a collection of utilities and28-Flask extensions. Explore the many `extensions29-<http://flask.pocoo.org/extensions/>`_ in the community, and look for patterns to30-build your own extensions if you do not find the tools you need.24+:ref:`signals`. You can provide custom classes for things like the25+request and response objects. Dig deeper on the APIs you use, and look26+for the customizations which are available out of the box in a Flask27+release. Look for ways in which your project can be refactored into a28+collection of utilities and Flask extensions. Explore the many29+:doc:`/extensions` in the community, and look for patterns to build your30+own extensions if you do not find the tools you need.31 32 Subclass.33 ---------34 61 unmodified lines96 ---------------------------97 98 The Flask developers keep the framework accessible to users with codebases big99 and small. If you find an obstacle in your way, caused by Flask, don't hesitate100-to contact the developers on the mailing list or IRC channel. The best way for100+to contact the developers on the mailing list or Discord server. The best way for101 the Flask and Flask extension developers to improve the tools for larger102 applications is getting feedback from users.modified:docs/extensiondev.rst+34 added-41 removed
1-.. _extension-dev:2-1 Flask Extension Development2 ===========================3 4 Flask, being a microframework, often requires some repetitive steps to get268 unmodified lines273 274 This documentation only touches the bare minimum for extension development.275 If you want to learn more, it's a very good idea to check out existing extensions276 on the `PyPI`_. If you feel lost there is still the `mailinglist`_ and the279-`IRC channel`_ to get some ideas for nice looking APIs. Especially if you do277+`Discord server`_ to get some ideas for nice looking APIs. Especially if you do278 something nobody before you did, it might be a very good idea to get some more279 input. This not only generates useful feedback on what people might want from280 an extension, but also avoids having multiple developers working in isolation281 on pretty much the same problem.7 unmodified lines289 290 Approved Extensions291 -------------------292 295-Flask also has the concept of approved extensions. Approved extensions296-are tested as part of Flask itself to ensure extensions do not break on297-new releases. If you want your own extension to be approved you have to298-follow these guidelines:293+Flask previously had the concept of approved extensions. These came with294+some vetting of support and compatibility. While this list became too295+difficult to maintain over time, the guidelines are still relevant to296+all extensions maintained and developed today, as they help the Flask297+ecosystem remain consistent and compatible.298 299 0. An approved Flask extension requires a maintainer. In the event an301- extension author would like to move beyond the project, the project should302- find a new maintainer including full source hosting transition and PyPI303- access. If no maintainer is available, give access to the Flask core team.304-1. An approved Flask extension must provide exactly one package or module305- named ``flask_extensionname``.306-2. It must ship a testing suite that can either be invoked with ``make test``307- or ``python setup.py test``. For test suites invoked with ``make308- test`` the extension has to ensure that all dependencies for the test309- are installed automatically. If tests are invoked with ``python setup.py310- test``, test dependencies can be specified in the :file:`setup.py` file.311- The test suite also has to be part of the distribution.312-3. APIs of approved extensions will be checked for the following313- characteristics:300+ extension author would like to move beyond the project, the project301+ should find a new maintainer and transfer access to the repository,302+ documentation, PyPI, and any other services. If no maintainer303+ is available, give access to the Pallets core team.304+1. The naming scheme is *Flask-ExtensionName* or *ExtensionName-Flask*.305+ It must provide exactly one package or module named306+ ``flask_extension_name``.307+2. The extension must be BSD or MIT licensed. It must be open source308+ and publicly available.309+3. The extension's API must have the following characteristics:310 315- - an approved extension has to support multiple applications316- running in the same Python process.317- - it must be possible to use the factory pattern for creating318- applications.311+ - It must support multiple applications running in the same Python312+ process. Use ``current_app`` instead of ``self.app``, store313+ configuration and state per application instance.314+ - It must be possible to use the factory pattern for creating315+ applications. Use the ``ext.init_app()`` pattern.316 320-4. The license must be BSD/MIT/WTFPL licensed.321-5. The naming scheme for official extensions is *Flask-ExtensionName* or322- *ExtensionName-Flask*.323-6. Approved extensions must define all their dependencies in the324- :file:`setup.py` file unless a dependency cannot be met because it is not325- available on PyPI.326-7. The documentation must use the ``flask`` theme from the327- `Official Pallets Themes`_.328-8. The setup.py description (and thus the PyPI description) has to329- link to the documentation, website (if there is one) and there330- must be a link to automatically install the development version331- (``PackageName==dev``).332-9. The ``zip_safe`` flag in the setup script must be set to ``False``,333- even if the extension would be safe for zipping.334-10. An extension currently has to support Python 3.4 and newer and 2.7.317+4. From a clone of the repository, an extension with its dependencies318+ must be installable with ``pip install -e .``.319+5. It must ship a testing suite that can be invoked with ``tox -e py``320+ or ``pytest``. If not using ``tox``, the test dependencies should be321+ specified in a ``requirements.txt`` file. The tests must be part of322+ the sdist distribution.323+6. The documentation must use the ``flask`` theme from the324+ `Official Pallets Themes`_. A link to the documentation or project325+ website must be in the PyPI metadata or the readme.326+7. The active versions of Python should be supported. As of 2020 this327+ means Python 3.5 and newer.328 329 330 .. _PyPI: https://pypi.org/search/?c=Framework+%3A%3A+Flask331 .. _OAuth extension: https://pythonhosted.org/Flask-OAuth/339-.. _mailinglist: http://flask.pocoo.org/mailinglist/340-.. _IRC channel: http://flask.pocoo.org/community/irc/332+.. _mailinglist: https://mail.python.org/mailman/listinfo/flask333+.. _Discord server: https://discord.gg/t6rrQZH334 .. _Official Pallets Themes: https://pypi.org/project/Pallets-Sphinx-Themes/modified:docs/extensions.rst+1 added-1 removed
41 unmodified lines42 -------------------43 44 While the `PyPI <pypi_>`_ contains many Flask extensions, you may45 not find an extension that fits your need. If this is the case, you can46-create your own. Read :ref:`extension-dev` to develop your own Flask46+create your own. Read :doc:`/extensiondev` to develop your own Flask47 extension.48 49 50 .. _pypi: https://pypi.org/search/?c=Framework+%3A%3A+Flaskmodified:docs/quickstart.rst+14 added-8 removed
865 unmodified lines866 docs for more information.867 868 Read more on :ref:`application-errors`.869 870-Hooking in WSGI Middlewares871----------------------------870+Hooking in WSGI Middleware871+--------------------------872 873-If you want to add a WSGI middleware to your application you can wrap the874-internal WSGI application. For example if you want to use one of the875-middlewares from the Werkzeug package to work around bugs in lighttpd, you876-can do it like this::873+To add WSGI middleware to your Flask application, wrap the application's874+``wsgi_app`` attribute. For example, to apply Werkzeug's875+:class:`~werkzeug.middlware.proxy_fix.ProxyFix` middleware for running876+behind Nginx:877 878- from werkzeug.contrib.fixers import LighttpdCGIRootFix879- app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app)878+.. code-block:: python879 880+ from werkzeug.middleware.proxy_fix import ProxyFix881+ app.wsgi_app = ProxyFix(app.wsgi_app)882+883+Wrapping ``app.wsgi_app`` instead of ``app`` means that ``app`` still884+points at your Flask application, not at the middleware, so you can885+continue to use and configure ``app`` directly.886+887 Using Flask Extensions888 ----------------------889 890 Extensions are packages that help you accomplish common tasks. For9 unmodified lines