Skip to content
Myr

Merge branch '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 12666af, 746d918 · Browse files · 10 files+72 added−72 removed
This commit

State

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

Diff stats

10 files+72 added−72 removed

  • other:+72 added−72 removed

10 files+72 added−72 removed

modified:docs/patterns/appdispatch.rst+2 added-2 removed
60 unmodified lines
6162For example you could have your main application run on ``/`` and your63backend interface on ``/backend``::6465 from werkzeug.wsgi import DispatcherMiddleware65 from werkzeug.middleware.dispatcher import DispatcherMiddleware66 from frontend_app import application as frontend67 from backend_app import application as backend6869 application = DispatcherMiddleware(frontend, {70 '/backend': backend70 '/backend': backend71 })727374Dispatch by Subdomain
114 unmodified lines
modified:docs/patterns/fileuploads.rst+1 added-1 removed
119 unmodified lines
120Alternatively you can register `uploaded_file` as `build_only` rule and121use the :class:`~werkzeug.wsgi.SharedDataMiddleware`. This also works with122older versions of Flask::123124 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 lines
modified:docs/patterns/index.rst+9 added-8 removed
1 unmodified line
23Patterns for Flask4==================56Certain things are common enough that the chances are high you will find7them in most web applications. For example quite a lot of applications8are using relational databases and user authentication. In that case,9chances are they will open a database connection at the beginning of the10request and get the information of the currently logged in user. At the11end of the request, the database connection is closed again.6Certain features and interactions are common enough that you will find7them in most web applications. For example, many applications use a8relational database and user authentication. They will open a database9connection at the beginning of the request and get the information for10the logged in user. At the end of the request, the database connection11is closed.1213There are more user contributed snippets and patterns in the `Flask14Snippet Archives <http://flask.pocoo.org/snippets/>`_.13These types of patterns may be a bit outside the scope of Flask itself,14but Flask makes it easy to implement them. Some common patterns are15collected in the following pages.1617.. toctree::18 :maxdepth: 219
27 unmodified lines
modified:docs/patterns/lazyloading.rst+1 added-1 removed
56 unmodified lines
57loaded upfront. The trick is to actually load the view function as needed.58This can be accomplished with a helper class that behaves just like a59function but internally imports the real function on first use::6061 from werkzeug import import_string, cached_property61 from werkzeug.utils import import_string, cached_property6263 class LazyView(object):6465 def __init__(self, import_name):
44 unmodified lines
modified:docs/patterns/viewdecorators.rst+1 added-1 removed
68 unmodified lines
69straightforward to read.7071The decorated function will then work as follows72731. get the unique cache key for the current request base on the current731. get the unique cache key for the current request based on the current74 path.752. get the value for that key from the cache. If the cache returned76 something we will return that value.773. otherwise the original function is called and the return value is
95 unmodified lines
modified:docs/appcontext.rst+1 added-1 removed
142 unmodified lines
143If you're writing an extension, :data:`g` should be reserved for user144code. You may store internal data on the context itself, but be sure to145use 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`.148149150Events and Signals151------------------
8 unmodified lines
modified:docs/becomingbig.rst+8 added-8 removed
19 unmodified lines
20Hook. Extend.21-------------2223The :ref:`api` docs are full of available overrides, hook points, and24:ref:`signals`. You can provide custom classes for things like the request and25response objects. Dig deeper on the APIs you use, and look for the26customizations which are available out of the box in a Flask release. Look for27ways in which your project can be refactored into a collection of utilities and28Flask extensions. Explore the many `extensions29<http://flask.pocoo.org/extensions/>`_ in the community, and look for patterns to30build your own extensions if you do not find the tools you need.24:ref:`signals`. You can provide custom classes for things like the25request and response objects. Dig deeper on the APIs you use, and look26for the customizations which are available out of the box in a Flask27release. Look for ways in which your project can be refactored into a28collection of utilities and Flask extensions. Explore the many29:doc:`/extensions` in the community, and look for patterns to build your30own extensions if you do not find the tools you need.3132Subclass.33---------34
61 unmodified lines
96---------------------------9798The Flask developers keep the framework accessible to users with codebases big99and small. If you find an obstacle in your way, caused by Flask, don't hesitate100to contact the developers on the mailing list or IRC channel. The best way for100to contact the developers on the mailing list or Discord server. The best way for101the Flask and Flask extension developers to improve the tools for larger102applications is getting feedback from users.
modified:docs/extensiondev.rst+34 added-41 removed
1.. _extension-dev:21Flask Extension Development2===========================34Flask, being a microframework, often requires some repetitive steps to get
268 unmodified lines
273274This documentation only touches the bare minimum for extension development.275If you want to learn more, it's a very good idea to check out existing extensions276on 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 do278something nobody before you did, it might be a very good idea to get some more279input. This not only generates useful feedback on what people might want from280an extension, but also avoids having multiple developers working in isolation281on pretty much the same problem.
7 unmodified lines
289290Approved Extensions291-------------------292295Flask also has the concept of approved extensions. Approved extensions296are tested as part of Flask itself to ensure extensions do not break on297new releases. If you want your own extension to be approved you have to298follow these guidelines:293Flask previously had the concept of approved extensions. These came with294some vetting of support and compatibility. While this list became too295difficult to maintain over time, the guidelines are still relevant to296all extensions maintained and developed today, as they help the Flask297ecosystem remain consistent and compatible.2982990. 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.3041. An approved Flask extension must provide exactly one package or module305 named ``flask_extensionname``.3062. 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.3123. 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.3041. The naming scheme is *Flask-ExtensionName* or *ExtensionName-Flask*.305 It must provide exactly one package or module named306 ``flask_extension_name``.3072. The extension must be BSD or MIT licensed. It must be open source308 and publicly available.3093. The extension's API must have the following characteristics:310315 - 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.3163204. The license must be BSD/MIT/WTFPL licensed.3215. The naming scheme for official extensions is *Flask-ExtensionName* or322 *ExtensionName-Flask*.3236. 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.3267. The documentation must use the ``flask`` theme from the327 `Official Pallets Themes`_.3288. 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``).3329. The ``zip_safe`` flag in the setup script must be set to ``False``,333 even if the extension would be safe for zipping.33410. An extension currently has to support Python 3.4 and newer and 2.7.3174. From a clone of the repository, an extension with its dependencies318 must be installable with ``pip install -e .``.3195. 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.3236. 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.3267. The active versions of Python should be supported. As of 2020 this327 means Python 3.5 and newer.328329330.. _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 lines
42-------------------4344While the `PyPI <pypi_>`_ contains many Flask extensions, you may45not find an extension that fits your need. If this is the case, you can46create your own. Read :ref:`extension-dev` to develop your own Flask46create your own. Read :doc:`/extensiondev` to develop your own Flask47extension.484950.. _pypi: https://pypi.org/search/?c=Framework+%3A%3A+Flask
modified:docs/quickstart.rst+14 added-8 removed
865 unmodified lines
866docs for more information.867868Read more on :ref:`application-errors`.869870Hooking in WSGI Middlewares871---------------------------870Hooking in WSGI Middleware871--------------------------872873If you want to add a WSGI middleware to your application you can wrap the874internal WSGI application. For example if you want to use one of the875middlewares from the Werkzeug package to work around bugs in lighttpd, you876can do it like this::873To 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 running876behind Nginx:877878 from werkzeug.contrib.fixers import LighttpdCGIRootFix879 app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app)878.. code-block:: python879880 from werkzeug.middleware.proxy_fix import ProxyFix881 app.wsgi_app = ProxyFix(app.wsgi_app)882883Wrapping ``app.wsgi_app`` instead of ``app`` means that ``app`` still884points at your Flask application, not at the middleware, so you can885continue to use and configure ``app`` directly.886887Using Flask Extensions888----------------------889890Extensions are packages that help you accomplish common tasks. For
9 unmodified lines