Skip to content

Commit e01b68e

Browse files
committed
update patterns, snippets, extensions docs
1 parent c074422 commit e01b68e

File tree

9 files changed

+73
-73
lines changed

9 files changed

+73
-73
lines changed

docs/appcontext.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ If you're writing an extension, :data:`g` should be reserved for user
144144
code. You may store internal data on the context itself, but be sure to
145145
use a sufficiently unique name. The current context is accessed with
146146
:data:`_app_ctx_stack.top <_app_ctx_stack>`. For more information see
147-
:doc:`extensiondev`.
147+
:doc:`/extensiondev`.
148148

149149

150150
Events and Signals

docs/becomingbig.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Hook. Extend.
2121
-------------
2222

2323
The :ref:`api` docs are full of available overrides, hook points, and
24-
:ref:`signals`. You can provide custom classes for things like the request and
25-
response objects. Dig deeper on the APIs you use, and look for the
26-
customizations which are available out of the box in a Flask release. Look for
27-
ways in which your project can be refactored into a collection of utilities and
28-
Flask extensions. Explore the many `extensions
29-
<http://flask.pocoo.org/extensions/>`_ in the community, and look for patterns to
30-
build your own extensions if you do not find the tools you need.
24+
:ref:`signals`. You can provide custom classes for things like the
25+
request and response objects. Dig deeper on the APIs you use, and look
26+
for the customizations which are available out of the box in a Flask
27+
release. Look for ways in which your project can be refactored into a
28+
collection of utilities and Flask extensions. Explore the many
29+
:doc:`/extensions` in the community, and look for patterns to build your
30+
own extensions if you do not find the tools you need.
3131

3232
Subclass.
3333
---------
@@ -96,6 +96,6 @@ Discuss with the community.
9696

9797
The Flask developers keep the framework accessible to users with codebases big
9898
and small. If you find an obstacle in your way, caused by Flask, don't hesitate
99-
to contact the developers on the mailing list or IRC channel. The best way for
99+
to contact the developers on the mailing list or Discord server. The best way for
100100
the Flask and Flask extension developers to improve the tools for larger
101101
applications is getting feedback from users.

docs/extensiondev.rst

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
.. _extension-dev:
2-
31
Flask Extension Development
42
===========================
53

@@ -276,7 +274,7 @@ Learn from Others
276274
This documentation only touches the bare minimum for extension development.
277275
If you want to learn more, it's a very good idea to check out existing extensions
278276
on the `PyPI`_. If you feel lost there is still the `mailinglist`_ and the
279-
`IRC channel`_ to get some ideas for nice looking APIs. Especially if you do
277+
`Discord server`_ to get some ideas for nice looking APIs. Especially if you do
280278
something nobody before you did, it might be a very good idea to get some more
281279
input. This not only generates useful feedback on what people might want from
282280
an extension, but also avoids having multiple developers working in isolation
@@ -292,50 +290,45 @@ API. And this can only work if collaboration happens early.
292290
Approved Extensions
293291
-------------------
294292

295-
Flask also has the concept of approved extensions. Approved extensions
296-
are tested as part of Flask itself to ensure extensions do not break on
297-
new releases. If you want your own extension to be approved you have to
298-
follow these guidelines:
293+
Flask previously had the concept of approved extensions. These came with
294+
some vetting of support and compatibility. While this list became too
295+
difficult to maintain over time, the guidelines are still relevant to
296+
all extensions maintained and developed today, as they help the Flask
297+
ecosystem remain consistent and compatible.
299298

300299
0. An approved Flask extension requires a maintainer. In the event an
301-
extension author would like to move beyond the project, the project should
302-
find a new maintainer including full source hosting transition and PyPI
303-
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 module
305-
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 ``make
308-
test`` the extension has to ensure that all dependencies for the test
309-
are installed automatically. If tests are invoked with ``python setup.py
310-
test``, test dependencies can be specified in the :file:`setup.py` file. The
311-
test suite also has to be part of the distribution.
312-
3. APIs of approved extensions will be checked for the following
313-
characteristics:
314-
315-
- an approved extension has to support multiple applications
316-
running in the same Python process.
317-
- it must be possible to use the factory pattern for creating
318-
applications.
319-
320-
4. The license must be BSD/MIT/WTFPL licensed.
321-
5. The naming scheme for official extensions is *Flask-ExtensionName* or
322-
*ExtensionName-Flask*.
323-
6. Approved extensions must define all their dependencies in the
324-
:file:`setup.py` file unless a dependency cannot be met because it is not
325-
available on PyPI.
326-
7. The documentation must use the ``flask`` theme from the
327-
`Official Pallets Themes`_.
328-
8. The setup.py description (and thus the PyPI description) has to
329-
link to the documentation, website (if there is one) and there
330-
must be a link to automatically install the development version
331-
(``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.
300+
extension author would like to move beyond the project, the project
301+
should find a new maintainer and transfer access to the repository,
302+
documentation, PyPI, and any other services. If no maintainer
303+
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 named
306+
``flask_extension_name``.
307+
2. The extension must be BSD or MIT licensed. It must be open source
308+
and publicly available.
309+
3. The extension's API must have the following characteristics:
310+
311+
- It must support multiple applications running in the same Python
312+
process. Use ``current_app`` instead of ``self.app``, store
313+
configuration and state per application instance.
314+
- It must be possible to use the factory pattern for creating
315+
applications. Use the ``ext.init_app()`` pattern.
316+
317+
4. From a clone of the repository, an extension with its dependencies
318+
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 be
321+
specified in a ``requirements.txt`` file. The tests must be part of
322+
the sdist distribution.
323+
6. The documentation must use the ``flask`` theme from the
324+
`Official Pallets Themes`_. A link to the documentation or project
325+
website must be in the PyPI metadata or the readme.
326+
7. The active versions of Python should be supported. As of 2020 this
327+
means Python 3.5 and newer.
335328

336329

337330
.. _PyPI: https://pypi.org/search/?c=Framework+%3A%3A+Flask
338331
.. _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/flask
333+
.. _Discord server: https://discord.gg/t6rrQZH
341334
.. _Official Pallets Themes: https://pypi.org/project/Pallets-Sphinx-Themes/

docs/extensions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Building Extensions
4343

4444
While the `PyPI <pypi_>`_ contains many Flask extensions, you may
4545
not find an extension that fits your need. If this is the case, you can
46-
create your own. Read :ref:`extension-dev` to develop your own Flask
46+
create your own. Read :doc:`/extensiondev` to develop your own Flask
4747
extension.
4848

4949

docs/patterns/appdispatch.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ dispatched based on prefix.
6262
For example you could have your main application run on ``/`` and your
6363
backend interface on ``/backend``::
6464

65-
from werkzeug.wsgi import DispatcherMiddleware
65+
from werkzeug.middleware.dispatcher import DispatcherMiddleware
6666
from frontend_app import application as frontend
6767
from backend_app import application as backend
6868

6969
application = DispatcherMiddleware(frontend, {
70-
'/backend': backend
70+
'/backend': backend
7171
})
7272

7373

docs/patterns/fileuploads.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Alternatively you can register `uploaded_file` as `build_only` rule and
121121
use the :class:`~werkzeug.wsgi.SharedDataMiddleware`. This also works with
122122
older versions of Flask::
123123

124-
from werkzeug import SharedDataMiddleware
124+
from werkzeug.middleware.shared_data import SharedDataMiddleware
125125
app.add_url_rule('/uploads/<filename>', 'uploaded_file',
126126
build_only=True)
127127
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {

docs/patterns/index.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
Patterns for Flask
44
==================
55

6-
Certain things are common enough that the chances are high you will find
7-
them in most web applications. For example quite a lot of applications
8-
are using relational databases and user authentication. In that case,
9-
chances are they will open a database connection at the beginning of the
10-
request and get the information of the currently logged in user. At the
11-
end of the request, the database connection is closed again.
6+
Certain features and interactions are common enough that you will find
7+
them in most web applications. For example, many applications use a
8+
relational database and user authentication. They will open a database
9+
connection at the beginning of the request and get the information for
10+
the logged in user. At the end of the request, the database connection
11+
is closed.
1212

13-
There are more user contributed snippets and patterns in the `Flask
14-
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 are
15+
collected in the following pages.
1516

1617
.. toctree::
1718
:maxdepth: 2

docs/patterns/lazyloading.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ loaded upfront. The trick is to actually load the view function as needed.
5858
This can be accomplished with a helper class that behaves just like a
5959
function but internally imports the real function on first use::
6060

61-
from werkzeug import import_string, cached_property
61+
from werkzeug.utils import import_string, cached_property
6262

6363
class LazyView(object):
6464

docs/quickstart.rst

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -824,16 +824,22 @@ docs for more information.
824824

825825
Read more on :ref:`application-errors`.
826826

827-
Hooking in WSGI Middlewares
828-
---------------------------
827+
Hooking in WSGI Middleware
828+
--------------------------
829829

830-
If you want to add a WSGI middleware to your application you can wrap the
831-
internal WSGI application. For example if you want to use one of the
832-
middlewares from the Werkzeug package to work around bugs in lighttpd, you
833-
can do it like this::
830+
To add WSGI middleware to your Flask application, wrap the application's
831+
``wsgi_app`` attribute. For example, to apply Werkzeug's
832+
:class:`~werkzeug.middlware.proxy_fix.ProxyFix` middleware for running
833+
behind Nginx:
834834

835-
from werkzeug.contrib.fixers import LighttpdCGIRootFix
836-
app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app)
835+
.. code-block:: python
836+
837+
from werkzeug.middleware.proxy_fix import ProxyFix
838+
app.wsgi_app = ProxyFix(app.wsgi_app)
839+
840+
Wrapping ``app.wsgi_app`` instead of ``app`` means that ``app`` still
841+
points at your Flask application, not at the middleware, so you can
842+
continue to use and configure ``app`` directly.
837843

838844
Using Flask Extensions
839845
----------------------

0 commit comments

Comments
 (0)