Merge remote-tracking branch 'origin/2.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 542cf30, e322f32 · Browse files · 10 files·+30 added−136 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+30 added−136 removed
- other:+30 added−136 removed
Provenance
- Commit
a25d234- Tree
e834d94- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
542cf30- Parent 2
e322f32
10 files changed+30 added−136 removed
modified:docs/patterns/packages.rst-4 removed
171 unmodified lines172 that we are not actually using the views in :file:`__init__.py` and just173 ensuring the module is imported and we are doing that at the bottom of174 the file.175 176- There are still some problems with that approach but if you want to use177- decorators there is no way around that. Check out the178- :doc:`/becomingbig` section for some inspiration how to deal with that.176 180-177 Working with Blueprints178 -----------------------179 180 If you have larger applications it's recommended to divide them into3 unmodified linesdeleted:docs/becomingbig.rst-100 removed
1-Becoming Big2-============3-4-Here are your options when growing your codebase or scaling your application.5-6-Read the Source.7-----------------8-9-Flask started in part to demonstrate how to build your own framework on top of10-existing well-used tools Werkzeug (WSGI) and Jinja (templating), and as it11-developed, it became useful to a wide audience. As you grow your codebase,12-don't just use Flask -- understand it. Read the source. Flask's code is13-written to be read; its documentation is published so you can use its internal14-APIs. Flask sticks to documented APIs in upstream libraries, and documents its15-internal utilities so that you can find the hook points needed for your16-project.17-18-Hook. Extend.19--------------20-21-The :doc:`/api` docs are full of available overrides, hook points, and22-:doc:`/signals`. You can provide custom classes for things like the23-request and response objects. Dig deeper on the APIs you use, and look24-for the customizations which are available out of the box in a Flask25-release. Look for ways in which your project can be refactored into a26-collection of utilities and Flask extensions. Explore the many27-:doc:`/extensions` in the community, and look for patterns to build your28-own extensions if you do not find the tools you need.29-30-Subclass.31----------32-33-The :class:`~flask.Flask` class has many methods designed for subclassing. You34-can quickly add or customize behavior by subclassing :class:`~flask.Flask` (see35-the linked method docs) and using that subclass wherever you instantiate an36-application class. This works well with :doc:`/patterns/appfactories`.37-See :doc:`/patterns/subclassing` for an example.38-39-Wrap with middleware.40----------------------41-42-The :doc:`/patterns/appdispatch` pattern shows in detail how to apply middleware. You43-can introduce WSGI middleware to wrap your Flask instances and introduce fixes44-and changes at the layer between your Flask application and your HTTP45-server. Werkzeug includes several `middlewares46-<https://werkzeug.palletsprojects.com/middleware/>`_.47-48-Fork.49------50-51-If none of the above options work, fork Flask. The majority of code of Flask52-is within Werkzeug and Jinja2. These libraries do the majority of the work.53-Flask is just the paste that glues those together. For every project there is54-the point where the underlying framework gets in the way (due to assumptions55-the original developers had). This is natural because if this would not be the56-case, the framework would be a very complex system to begin with which causes a57-steep learning curve and a lot of user frustration.58-59-This is not unique to Flask. Many people use patched and modified60-versions of their framework to counter shortcomings. This idea is also61-reflected in the license of Flask. You don't have to contribute any62-changes back if you decide to modify the framework.63-64-The downside of forking is of course that Flask extensions will most65-likely break because the new framework has a different import name.66-Furthermore integrating upstream changes can be a complex process,67-depending on the number of changes. Because of that, forking should be68-the very last resort.69-70-Scale like a pro.71------------------72-73-For many web applications the complexity of the code is less an issue than74-the scaling for the number of users or data entries expected. Flask by75-itself is only limited in terms of scaling by your application code, the76-data store you want to use and the Python implementation and webserver you77-are running on.78-79-Scaling well means for example that if you double the amount of servers80-you get about twice the performance. Scaling bad means that if you add a81-new server the application won't perform any better or would not even82-support a second server.83-84-There is only one limiting factor regarding scaling in Flask which are85-the context local proxies. They depend on context which in Flask is86-defined as being either a thread, process or greenlet. If your server87-uses some kind of concurrency that is not based on threads or greenlets,88-Flask will no longer be able to support these global proxies. However the89-majority of servers are using either threads, greenlets or separate90-processes to achieve concurrency which are all methods well supported by91-the underlying Werkzeug library.92-93-Discuss with the community.94----------------------------95-96-The Flask developers keep the framework accessible to users with codebases big97-and small. If you find an obstacle in your way, caused by Flask, don't hesitate98-to contact the developers on the mailing list or Discord server. The best way for99-the Flask and Flask extension developers to improve the tools for larger100-applications is getting feedback from users.modified:docs/cli.rst+1 added-3 removed
297 unmodified lines298 used for public variables, such as ``FLASK_APP``, while :file:`.env` should not299 be committed to your repository so that it can set private variables.300 301 Directories are scanned upwards from the directory you call ``flask``302-from to locate the files. The current working directory will be set to the303-location of the file, with the assumption that that is the top level project304-directory.302+from to locate the files.303 304 The files are only loaded by the ``flask`` command or calling305 :meth:`~Flask.run`. If you would like to load these files when running in306 production, you should call :func:`~cli.load_dotenv` manually.412 unmodified linesmodified:docs/design.rst-3 removed
165 unmodified lines166 large applications harder to maintain. However Flask is just not designed167 for large applications or asynchronous servers. Flask wants to make it168 quick and easy to write a traditional web application.169 170-Also see the :doc:`/becomingbig` section of the documentation for some171-inspiration for larger applications based on Flask.170 173-171 Async/await and ASGI support172 ----------------------------173 174 Flask supports ``async`` coroutines for view functions by executing the31 unmodified linesmodified:docs/extensiondev.rst+7 added-7 removed
269 unmodified lines270 -----------------271 272 This documentation only touches the bare minimum for extension development.273 If you want to learn more, it's a very good idea to check out existing extensions274-on the `PyPI`_. If you feel lost there is still the `mailinglist`_ and the275-`Discord server`_ to get some ideas for nice looking APIs. Especially if you do274+on `PyPI`_. If you feel lost there is `Discord Chat`_ or275+`GitHub Discussions`_ to get some ideas for nice looking APIs. Especially if you do276 something nobody before you did, it might be a very good idea to get some more277 input. This not only generates useful feedback on what people might want from278 an extension, but also avoids having multiple developers working in isolation279 on pretty much the same problem.280 281-Remember: good API design is hard, so introduce your project on the282-mailing list, and let other developers give you a helping hand with283-designing the API.281+Remember: good API design is hard, so introduce your project on282+`Discord Chat`_ or `GitHub Discussions`_, and let other developers give283+you a helping hand with designing the API.284 285 The best Flask extensions are extensions that share common idioms for the286 API. And this can only work if collaboration happens early.287 38 unmodified lines326 December 2021. Use ``python_requires=">= 3.7"`` in ``setup.py`` to327 indicate supported versions.328 329 .. _PyPI: https://pypi.org/search/?c=Framework+%3A%3A+Flask330-.. _mailinglist: https://mail.python.org/mailman/listinfo/flask331-.. _Discord server: https://discord.gg/pallets330+.. _Discord Chat: https://discord.gg/pallets331+.. _GitHub Discussions: https://github.com/pallets/flask/discussions332 .. _Official Pallets Themes: https://pypi.org/project/Pallets-Sphinx-Themes/modified:docs/foreword.rst+4 added-4 removed
45 unmodified lines46 SQLAlchemy or another database tool, introduce non-relational data persistence47 as appropriate, and take advantage of framework-agnostic tools built for WSGI,48 the Python web interface.49 50-Flask includes many hooks to customize its behavior. Should you need more51-customization, the Flask class is built for subclassing. If you are interested52-in that, check out the :doc:`becomingbig` chapter. If you are curious about53-the Flask design principles, head over to the section about :doc:`design`.50+Flask includes many hooks to customize its behavior. Should you need51+more customization, the Flask class is built for subclassing. If you are52+curious about the Flask design principles, head over to the section53+about :doc:`design`.modified:docs/index.rst-1 removed
56 unmodified lines57 server58 shell59 patterns/index60 deploying/index61- becomingbig61 async-await62 63 64 API Reference26 unmodified linesmodified:src/flask/cli.py+8 added-1 removed
7 unmodified lines8 from functools import update_wrapper9 from operator import attrgetter10 from threading import Lock11 from threading import Thread12+from typing import Any13+from typing import TYPE_CHECKING14 15 import click16 from werkzeug.utils import import_string17 19 unmodified lines37 #38 # We technically have importlib.metadata on 3.8+,39 # but the API changed in 3.10, so use the backport40 # for consistency.41+ if TYPE_CHECKING:42+ metadata: Any43+ else:44+ # we do this to avoid a version dependent mypy error45+ # because importlib_metadata is not installed in python3.10+39- import importlib_metadata as metadata # type: ignore46+ import importlib_metadata as metadata47 48 49 class NoAppException(click.UsageError):50 """Raised if an application cannot be found or loaded."""949 unmodified linesmodified:.gitignore-1 removed
9 unmodified lines10 dist/11 build/12 *.egg13 *.egg-info/14-_mailinglist14 .tox/15 .cache/16 .pytest_cache/17 .idea/8 unmodified linesmodified:CONTRIBUTING.rst+10 added-12 removed
12 unmodified lines13 own code:14 15 - The ``#questions`` channel on our Discord chat:16 https://discord.gg/pallets17-- The mailing list flask@python.org for long term discussion or larger18- issues.17 - Ask on `Stack Overflow`_. Search with Google first using:18 ``site:stackoverflow.com flask {search term, exception message, etc.}``21-- Ask on our `GitHub Discussions`_.19+- Ask on our `GitHub Discussions`_ for long term discussion or larger20+ questions.21 22 .. _Stack Overflow: https://stackoverflow.com/questions/tagged/flask?tab=Frequent23 .. _GitHub Discussions: https://github.com/pallets/flask/discussions24 71 unmodified lines96 $ git remote add fork https://github.com/{username}/flask97 98 - Create a virtualenv.99 101- .. tabs::100 103- .. group-tab:: Linux/macOS101+ - Linux/macOS102 105- .. code-block:: text103+ .. code-block:: text104 107- $ python3 -m venv env108- $ . env/bin/activate105+ $ python3 -m venv env106+ $ . env/bin/activate107 110- .. group-tab:: Windows108+ - Windows109 112- .. code-block:: text110+ .. code-block:: text111 114- > py -3 -m venv env115- > env\Scripts\activate112+ > py -3 -m venv env113+ > env\Scripts\activate114 115 - Upgrade pip and setuptools.116 117 .. code-block:: text110 unmodified lines