Skip to content
Myr

remove unused ref directives

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

replace page refs with doc directives

authored by David Lord · committed by David Lord · parent f2f027d · Browse files · 55 files+129 added−221 removed
This commit

State

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

Diff stats

55 files+129 added−221 removed

  • other:+129 added−221 removed

55 files+129 added−221 removed

modified:docs/deploying/fastcgi.rst-2 removed
1.. _deploying-fastcgi:21FastCGI2=======34FastCGI is a deployment option on servers like `nginx`_, `lighttpd`_, and
234 unmodified lines
modified:docs/deploying/index.rst-2 removed
1.. _deployment:21Deployment Options2==================34While lightweight and easy to use, **Flask's built-in server is not suitable
29 unmodified lines
modified:docs/deploying/mod_wsgi.rst-2 removed
1.. _mod_wsgi-deployment:21mod_wsgi (Apache)2=================34If you are using the `Apache`_ webserver, consider using `mod_wsgi`_.
212 unmodified lines
modified:docs/deploying/uwsgi.rst-2 removed
1.. _deploying-uwsgi:21uWSGI2=====34uWSGI is a deployment option on servers like `nginx`_, `lighttpd`_, and
67 unmodified lines
modified:docs/deploying/wsgi-standalone.rst-2 removed
1.. _deploying-wsgi-standalone:21Standalone WSGI Containers2==========================34There are popular servers written in Python that contain WSGI applications and
149 unmodified lines
modified:docs/patterns/appdispatch.rst+10 added-12 removed
1.. _app-dispatch:21Application Dispatching2=======================34Application dispatching is the process of combining multiple Flask
2 unmodified lines
7Django and a Flask application in the same interpreter side by side if8you want. The usefulness of this depends on how the applications work9internally.1013The fundamental difference from the :ref:`module approach14<larger-applications>` is that in this case you are running the same or15different Flask applications that are entirely isolated from each other.16They run different configurations and are dispatched on the WSGI level.11The fundamental difference from :doc:`packages` is that in this case you12are running the same or different Flask applications that are entirely13isolated from each other. They run different configurations and are14dispatched on the WSGI level.151617Working with this Document18--------------------------1922Each of the techniques and examples below results in an ``application`` object23that can be run with any WSGI server. For production, see :ref:`deployment`.24For development, Werkzeug provides a builtin server for development available25at :func:`werkzeug.serving.run_simple`::20Each of the techniques and examples below results in an ``application``21object that can be run with any WSGI server. For production, see22:doc:`/deploying/index`. For development, Werkzeug provides a server23through :func:`werkzeug.serving.run_simple`::2425 from werkzeug.serving import run_simple26 run_simple('localhost', 5000, application, use_reloader=True)2728Note that :func:`run_simple <werkzeug.serving.run_simple>` is not intended for31use in production. Use a :ref:`full-blown WSGI server <deployment>`.29use in production. Use a production WSGI server. See :doc:`/deploying/index`.3031In order to use the interactive debugger, debugging must be enabled both on32the application and the simple server. Here is the "hello world" example with33debugging and :func:`run_simple <werkzeug.serving.run_simple>`::
42 unmodified lines
76with different configurations. Assuming the application is created inside77a function and you can call that function to instantiate it, that is78really easy to implement. In order to develop your application to support79creating new instances in functions have a look at the82:ref:`app-factories` pattern.80:doc:`appfactories` pattern.8182A very common example would be creating applications per subdomain. For83instance you configure your webserver to dispatch all requests for all84subdomains to your application and you then use the subdomain information
102 unmodified lines
modified:docs/patterns/appfactories.rst+1 added-3 removed
1.. _app-factories:21Application Factories2=====================34If you are already using packages and blueprints for your application7(:ref:`blueprints`) there are a couple of really nice ways to further improve5(:doc:`/blueprints`) there are a couple of really nice ways to further improve6the experience. A common pattern is creating the application object when7the blueprint is imported. But if you move the creation of this object8into a function, you can then create multiple instances of this app later.9
106 unmodified lines
modified:docs/patterns/caching.rst-2 removed
1.. _caching-pattern:21Caching2=======34When your application runs slow, throw some caches in. Well, at least
12 unmodified lines
modified:docs/patterns/deferredcallbacks.rst-2 removed
1.. _deferred-callbacks:21Deferred Request Callbacks2==========================34One of the design principles of Flask is that response objects are created and
40 unmodified lines
modified:docs/patterns/distribute.rst+6 added-9 removed
1.. _distribute-deployment:21Deploying with Setuptools2=========================34`Setuptools`_, is an extension library that is commonly used to
15 unmodified lines
20Flask itself, and all the libraries you can find on PyPI are distributed with21either setuptools or distutils.2223In this case we assume your application is called26:file:`yourapplication.py` and you are not using a module, but a :ref:`package27<larger-applications>`. If you have not yet converted your application into28a package, head over to the :ref:`larger-applications` pattern to see29how this can be done.24:file:`yourapplication.py` and you are not using a module, but a25package. If you have not yet converted your application into a package,26head over to :doc:`packages` to see how this can be done.2728A working deployment with setuptools is the first step into more complex29and more automated deployment scenarios. If you want to fully automate33the process, also read the :ref:`fabric-deployment` chapter.30the process, also read the :doc:`fabric` chapter.3132Basic Setup Script33------------------3435Because you have Flask installed, you have setuptools available on your system.36Flask already depends upon setuptools.3741Standard disclaimer applies: :ref:`you better use a virtualenv42<virtualenv>`.38Standard disclaimer applies: :ref:`use a virtualenv39<install-create-env>`.4041Your setup code always goes into a file named :file:`setup.py` next to your42application. The name of the file is only convention, but because43everybody will look for a file with that name, you better not change it.
127 unmodified lines
modified:docs/patterns/errorpages.rst+2 added-4 removed
1.. _errorpages:21Custom Error Pages2==================34Flask comes with a handy :func:`~flask.abort` function that aborts a
33 unmodified lines
38*500 Internal Server Error*39 Usually happens on programming errors or if the server is overloaded.40 A terribly good idea is to have a nice page there, because your41 application *will* fail sooner or later (see also:44 :ref:`application-errors`).42 :doc:`/errorhandling`).434445Error Handlers46--------------
24 unmodified lines
71 def page_not_found(e):72 # note that we set the 404 status explicitly73 return render_template('404.html'), 4047477When using the :ref:`application factory pattern <app-factories>`::75When using the :doc:`appfactories`::7677 from flask import Flask, render_template7879 def page_not_found(e):
44 unmodified lines
modified:docs/patterns/fabric.rst+5 added-7 removed
1.. _fabric-deployment:21Deploying with Fabric2=====================34`Fabric`_ is a tool for Python similar to Makefiles but with the ability5to execute commands on a remote server. In combination with a properly8set up Python package (:ref:`larger-applications`) and a good concept for9configurations (:ref:`config`) it is very easy to deploy Flask6set up Python package (:doc:`packages`) and a good concept for7configurations (:doc:`/config`) it is very easy to deploy Flask8applications to external servers.910Before we get started, here a quick checklist of things we have to ensure11upfront:1213- Fabric 1.0 has to be installed locally. This tutorial assumes the14 latest version of Fabric.15- The application already has to be a package and requires a working18 :file:`setup.py` file (:ref:`distribute-deployment`).16 :file:`setup.py` file (:doc:`distribute`).17- In the following example we are using `mod_wsgi` for the remote18 servers. You can of course use your own favourite server there, but19 for this example we chose Apache + `mod_wsgi` because it's very easy20 to setup and has a simple way to reload applications without root
77 unmodified lines
98993. Create a new Apache config for ``yourapplication`` and activate it.100 Make sure to activate watching for changes of the ``.wsgi`` file so101 that we can automatically reload the application by touching it.104 (See :ref:`mod_wsgi-deployment` for more information)102 See :doc:`/deploying/mod_wsgi`.103104So now the question is, where do the :file:`application.wsgi` and105:file:`application.cfg` files come from?106
14 unmodified lines
121 app = Flask(__name__)122 app.config.from_object('yourapplication.default_config')123 app.config.from_envvar('YOURAPPLICATION_CONFIG')124127This approach is explained in detail in the :ref:`config` section of the125This approach is explained in detail in the :doc:`/config` section of the126documentation.127128The Configuration File129----------------------
55 unmodified lines
modified:docs/patterns/fileuploads.rst+1 added-3 removed
1.. _uploading-files:21Uploading Files2===============34Ah yes, the good old problem of file uploads. The basic idea of file
31 unmodified lines
36Why do we limit the extensions that are allowed? You probably don't want37your users to be able to upload everything there if the server is directly38sending out the data to the client. That way you can make sure that users39are not able to upload HTML files that would cause XSS problems (see42:ref:`xss`). Also make sure to disallow ``.php`` files if the server40:ref:`security-xss`). Also make sure to disallow ``.php`` files if the server41executes them, but who has PHP installed on their server, right? :)4243Next the functions that check if an extension is valid and that uploads44the file and redirects the user to the URL for the uploaded file::
144 unmodified lines
modified:docs/patterns/flashing.rst-2 removed
1.. _message-flashing-pattern:21Message Flashing2================34Good applications and user interfaces are all about feedback. If the user
144 unmodified lines
modified:docs/patterns/index.rst-2 removed
1.. _patterns:21Patterns for Flask2==================34Certain features and interactions are common enough that you will find
40 unmodified lines
deleted:docs/patterns/mongokit.rst-7 removed
1:orphan:23MongoDB with MongoKit4=====================56MongoKit is no longer maintained. See :doc:`/patterns/mongoengine`7instead.
modified:docs/patterns/packages.rst+5 added-9 removed
1.. _larger-applications:1Large Applications as Packages2==============================33Larger Applications4===================54Imagine a simple flask application structure that looks like this::56 /yourapplication7 yourapplication.py
6 unmodified lines
14 ...1516While this is fine for small applications, for larger applications17it's a good idea to use a package instead of a module.20The :ref:`tutorial <tutorial>` is structured to use the package pattern,18The :doc:`/tutorial/index` is structured to use the package pattern,19see the :gh:`example code <examples/tutorial>`.2021Simple Packages22---------------
103 unmodified lines
126 the file.127128 There are still some problems with that approach but if you want to use129 decorators there is no way around that. Check out the132 :ref:`becomingbig` section for some inspiration how to deal with that.130 :doc:`/becomingbig` section for some inspiration how to deal with that.131132135.. _working-with-modules:136133Working with Blueprints134-----------------------135136If you have larger applications it's recommended to divide them into137smaller groups where each group is implemented with the help of a138blueprint. For a gentle introduction into this topic refer to the143:ref:`blueprints` chapter of the documentation.139:doc:`/blueprints` chapter of the documentation.
modified:docs/patterns/sqlalchemy.rst+3 added-6 removed
1.. _sqlalchemy-pattern:21SQLAlchemy in Flask2===================34Many people prefer `SQLAlchemy`_ for database access. In this case it's5encouraged to use a package instead of a module for your flask application8and drop the models into a separate module (:ref:`larger-applications`).9While that is not necessary, it makes a lot of sense.6and drop the models into a separate module (:doc:`packages`). While that7is not necessary, it makes a lot of sense.89There are four very common ways to use SQLAlchemy. I will outline each10of them here:11
94 unmodified lines
106>>> User.query.filter(User.name == 'admin').first()107<User 'admin'>108109.. _SQLAlchemy: https://www.sqlalchemy.org/112.. _declarative:113 https://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/110.. _declarative: https://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/111112Manual Object Relational Mapping113--------------------------------114
101 unmodified lines
modified:docs/patterns/sqlite3.rst-3 removed
1.. _sqlite3:21Using SQLite 3 with Flask2=========================34In Flask you can easily implement the opening of database connections on
54 unmodified lines
5960 with app.app_context():61 # now you can use get_db()6265.. _easy-querying:6364Easy Querying65-------------66
85 unmodified lines
modified:docs/patterns/templateinheritance.rst-2 removed
1.. _template-inheritance:21Template Inheritance2====================34The most powerful part of Jinja is template inheritance. Template inheritance
64 unmodified lines
modified:docs/patterns/viewdecorators.rst+3 added-3 removed
57 unmodified lines
5859Imagine you have a view function that does an expensive calculation and60because of that you would like to cache the generated results for a61certain amount of time. A decorator would be nice for that. We're62assuming you have set up a cache like mentioned in :ref:`caching-pattern`.62assuming you have set up a cache like mentioned in :doc:`caching`.6364Here is an example cache function. It generates the cache key from a65specific prefix (actually a format string) and the current path of the66request. Notice that we are using a function that first creates the
28 unmodified lines
95 return rv96 return decorated_function97 return decorator9899Notice that this assumes an instantiated `cache` object is available, see100:ref:`caching-pattern` for more information.99Notice that this assumes an instantiated ``cache`` object is available, see100:doc:`caching`.101102103Templating Decorator104--------------------
67 unmodified lines
modified:docs/patterns/wtforms.rst+2 added-2 removed
7 unmodified lines
8forms, you might want to give it a try.910When you are working with WTForms you have to define your forms as classes11first. I recommend breaking up the application into multiple modules12(:ref:`larger-applications`) for that and adding a separate module for the12(:doc:`packages`) for that and adding a separate module for the13forms.1415.. admonition:: Getting the most out of WTForms with an Extension16
37 unmodified lines
54 return redirect(url_for('login'))55 return render_template('register.html', form=form)5657Notice we're implying that the view is using SQLAlchemy here58(:ref:`sqlalchemy-pattern`), but that's not a requirement, of course. Adapt58(:doc:`sqlalchemy`), but that's not a requirement, of course. Adapt59the code as necessary.6061Things to remember:62
64 unmodified lines
modified:docs/tutorial/database.rst+4 added-4 removed
140 unmodified lines
141read from the file.142143:func:`click.command` defines a command line command called ``init-db``144that calls the ``init_db`` function and shows a success message to the145user. You can read :ref:`cli` to learn more about writing commands.145user. You can read :doc:`/cli` to learn more about writing commands.146147148Register with the Application149-----------------------------
45 unmodified lines
195196 If you're still running the server from the previous page, you can197 either stop the server, or run this command in a new terminal. If198 you use a new terminal, remember to change to your project directory199 and activate the env as described in :ref:`install-activate-env`.200 You'll also need to set ``FLASK_APP`` and ``FLASK_ENV`` as shown on201 the previous page.199 and activate the env as described in :doc:`/installation`. You'll200 also need to set ``FLASK_APP`` and ``FLASK_ENV`` as shown on the201 previous page.202203Run the ``init-db`` command:204205.. code-block:: none
8 unmodified lines
modified:docs/tutorial/index.rst+3 added-5 removed
1.. _tutorial:21Tutorial2========34.. toctree::
27 unmodified lines
3233.. _official tutorial: https://docs.python.org/3/tutorial/3435While it's designed to give a good starting point, the tutorial doesn't38cover all of Flask's features. Check out the :ref:`quickstart` for an36cover all of Flask's features. Check out the :doc:`/quickstart` for an37overview of what Flask can do, then dive into the docs to find out more.38The tutorial only uses what's provided by Flask and Python. In another41project, you might decide to use :ref:`extensions` or other libraries to42make some tasks simpler.39project, you might decide to use :doc:`/extensions` or other libraries40to make some tasks simpler.4142.. image:: flaskr_login.png43 :align: center44 :class: screenshot
20 unmodified lines
modified:docs/tutorial/next.rst+2 added-2 removed
7 unmodified lines
8different due to the step-by-step nature of the tutorial.910There's a lot more to Flask than what you've seen so far. Even so,11you're now equipped to start developing your own web applications. Check12out the :ref:`quickstart` for an overview of what Flask can do, then12out the :doc:`/quickstart` for an overview of what Flask can do, then13dive into the docs to keep learning. Flask uses `Jinja`_, `Click`_,14`Werkzeug`_, and `ItsDangerous`_ behind the scenes, and they all have15their own documentation too. You'll also be interested in16:ref:`extensions` which make tasks like working with the database or16:doc:`/extensions` which make tasks like working with the database or17validating form data easier and more powerful.1819If you want to keep developing your Flaskr project, here are some ideas20for what to try next:
18 unmodified lines
modified:docs/advanced_foreword.rst-2 removed
1.. _advanced_foreword:21Foreword for Experienced Programmers2====================================34Thread-Locals in Flask
42 unmodified lines
modified:docs/api.rst+4 added-8 removed
1.. _api:21API2===34.. module:: flask
318 unmodified lines
323 </script>324325.. admonition:: Auto-Sort JSON Keys326329 The configuration variable ``JSON_SORT_KEYS`` (:ref:`config`) can be330 set to false to stop Flask from auto-sorting keys. By default sorting327 The configuration variable :data:`JSON_SORT_KEYS` can be set to328 ``False`` to stop Flask from auto-sorting keys. By default sorting329 is enabled and outside of the app context sorting is turned on.330333 Notice that disabling key sorting can cause issues when using content334 based HTTP caches and Python's hash randomization feature.331 Notice that disabling key sorting can cause issues when using332 content based HTTP caches and Python's hash randomization feature.333334.. autofunction:: jsonify335336.. autofunction:: dumps
294 unmodified lines
631632633.. _blinker: https://pypi.org/project/blinker/634637.. _class-based-views:635636Class-Based Views637-----------------638
118 unmodified lines
757 implicitly added and handled by the standard request758 handling. They have to be specified as keyword arguments.759=============== ==========================================================760764.. _view-func-options:761762View Function Options763---------------------764
66 unmodified lines
modified:docs/appcontext.rst-2 removed
1.. currentmodule:: flask23.. _app-context:43The Application Context4=======================56The application context keeps track of the application-level data during
151 unmodified lines
modified:docs/becomingbig.rst+4 added-6 removed
1.. _becomingbig:21Becoming Big2============34Here are your options when growing your codebase or scaling your application.
12 unmodified lines
1718Hook. Extend.19-------------2023The :ref:`api` docs are full of available overrides, hook points, and24:ref:`signals`. You can provide custom classes for things like the21The :doc:`/api` docs are full of available overrides, hook points, and22:doc:`/signals`. You can provide custom classes for things like the23request and response objects. Dig deeper on the APIs you use, and look24for the customizations which are available out of the box in a Flask25release. Look for ways in which your project can be refactored into a26collection of utilities and Flask extensions. Explore the many
5 unmodified lines
3233The :class:`~flask.Flask` class has many methods designed for subclassing. You34can quickly add or customize behavior by subclassing :class:`~flask.Flask` (see35the linked method docs) and using that subclass wherever you instantiate an38application class. This works well with :ref:`app-factories`.36application class. This works well with :doc:`/patterns/appfactories`.37See :doc:`/patterns/subclassing` for an example.3839Wrap with middleware.40---------------------4144The :ref:`app-dispatch` chapter shows in detail how to apply middleware. You42The :doc:`/patterns/appdispatch` pattern shows in detail how to apply middleware. You43can introduce WSGI middleware to wrap your Flask instances and introduce fixes44and changes at the layer between your Flask application and your HTTP45server. Werkzeug includes several `middlewares46<https://werkzeug.palletsprojects.com/middleware/>`_.
54 unmodified lines
modified:docs/blueprints.rst+4 added-5 removed
1.. _blueprints:21Modular Applications with Blueprints2====================================34.. currentmodule:: flask
29 unmodified lines
3435A blueprint in Flask is not a pluggable app because it is not actually an36application -- it's a set of operations which can be registered on an37application, even multiple times. Why not have multiple application40objects? You can do that (see :ref:`app-dispatch`), but your applications41will have separate configs and will be managed at the WSGI layer.38objects? You can do that (see :doc:`/patterns/appdispatch`), but your39applications will have separate configs and will be managed at the WSGI40layer.4142Blueprints instead provide separation at the Flask level, share43application config, and can change an application object as necessary with44being registered. The downside is that you cannot unregister a blueprint
227 unmodified lines
272 return jsonify_error(ex)273 else:274 return ex275277More information on error handling see :ref:`errorpages`.276More information on error handling see :doc:`/patterns/errorpages`.
modified:docs/changelog.rst+2 added-2 removed
1Changelog2=========1Changes2=======34.. include:: ../CHANGES.rst
modified:docs/cli.rst+1 added-3 removed
1.. currentmodule:: flask23.. _cli:43Command Line Interface4======================56Installing Flask installs the ``flask`` script, a `Click`_ command line
89 unmodified lines
9697.. warning:: Do not use this command to run your application in production.98 Only use the development server during development. The development server99 is provided for convenience, but is not designed to be particularly secure,102 stable, or efficient. See :ref:`deployment` for how to run in production.100 stable, or efficient. See :doc:`/deploying/index` for how to run in production.101102103Open a Shell104------------
437 unmodified lines
modified:docs/config.rst+3 added-5 removed
1.. _config:21Configuration Handling2======================34Applications need some kind of configuration. There are different settings
270 unmodified lines
275276 Inform the application what path it is mounted under by the application /277 web server. This is used for generating URLs outside the context of a278 request (inside a request, the dispatcher is responsible for setting281 ``SCRIPT_NAME`` instead; see :ref:`Application Dispatching <app-dispatch>`279 ``SCRIPT_NAME`` instead; see :doc:`/patterns/appdispatch`280 for examples of dispatch configuration).281282 Will be used for the session cookie path if ``SESSION_COOKIE_PATH`` is not283 set.
112 unmodified lines
396397Configuration becomes more useful if you can store it in a separate file,398ideally located outside the actual application package. This makes399packaging and distributing your application possible via various package402handling tools (:ref:`distribute-deployment`) and finally modifying the400handling tools (:doc:`/patterns/distribute`) and finally modifying the401configuration file afterwards.402403So a common pattern is this::404
220 unmodified lines
625 and exports the development configuration for you.626- Use a tool like `fabric`_ in production to push code and627 configurations separately to the production server(s). For some628 details about how to do that, head over to the631 :ref:`fabric-deployment` pattern.629 :doc:`/patterns/fabric` pattern.630631.. _fabric: https://www.fabfile.org/632633
82 unmodified lines
modified:docs/design.rst+2 added-4 removed
1.. _design:21Design Decisions in Flask2=========================34If you are curious why Flask does certain things the way it does and not
69 unmodified lines
74to the application object :meth:`~flask.Flask.wsgi_app`).7576Furthermore this design makes it possible to use a factory function to77create the application which is very helpful for unit testing and similar80things (:ref:`app-factories`).78things (:doc:`/patterns/appfactories`).7980The Routing System81------------------82
83 unmodified lines
166large applications harder to maintain. However Flask is just not designed167for large applications or asynchronous servers. Flask wants to make it168quick and easy to write a traditional web application.169172Also see the :ref:`becomingbig` section of the documentation for some170Also see the :doc:`/becomingbig` section of the documentation for some171inspiration for larger applications based on Flask.172173174What Flask is, What Flask is Not
15 unmodified lines
modified:docs/errorhandling.rst+1 added-4 removed
1.. _application-errors:21Application Errors2==================34.. versionadded:: 0.3
60 unmodified lines
65 <https://docs.sentry.io/platforms/python/>`_ for more information.66* `Getting started with Sentry <https://docs.sentry.io/quickstart/?platform=python>`_67* `Flask-specific documentation <https://docs.sentry.io/platforms/python/flask/>`_.6871.. _error-handlers:6970Error handlers71--------------72
162 unmodified lines
235Debugging Application Errors236============================237238For production applications, configure your application with logging and242notifications as described in :ref:`application-errors`. This section provides239notifications as described in :doc:`/logging`. This section provides240pointers when debugging deployment configuration and digging deeper with a241full-featured Python debugger.242243
51 unmodified lines
modified:docs/extensiondev.rst+6 added-5 removed
25 unmodified lines
2627But what do extensions look like themselves? An extension has to ensure28that it works with multiple Flask application instances at once. This is29a requirement because many people will use patterns like the30:ref:`app-factories` pattern to create their application as needed to aid31unittests and to support multiple configurations. Because of that it is32crucial that your application supports that kind of behavior.30:doc:`/patterns/appfactories` pattern to create their application as31needed to aid unittests and to support multiple configurations. Because32of that it is crucial that your application supports that kind of33behavior.3435Most importantly the extension must be shipped with a :file:`setup.py` file and36registered on PyPI. Also the development checkout link should work so37that people can easily install the development version into their
79 unmodified lines
117-----------------------118119Many extensions will need some kind of initialization step. For example,120consider an application that's currently connecting to SQLite like the120documentation suggests (:ref:`sqlite3`). So how does the extension121know the name of the application object?121documentation suggests (:doc:`/patterns/sqlite3`). So how does the122extension know the name of the application object?123124Quite simple: you pass it to it.125126There are two recommended ways for an extension to initialize:
210 unmodified lines
modified:docs/extensions.rst-2 removed
1.. _extensions:21Extensions2==========34Extensions are extra packages that add functionality to a Flask
44 unmodified lines
modified:docs/foreword.rst+2 added-5 removed
47 unmodified lines
48the Python web interface.4950Flask includes many hooks to customize its behavior. Should you need more51customization, the Flask class is built for subclassing. If you are interested52in that, check out the :ref:`becomingbig` chapter. If you are curious about53the Flask design principles, head over to the section about :ref:`design`.5455Continue to :ref:`installation`, the :ref:`quickstart`, or the56:ref:`advanced_foreword`.52in that, check out the :doc:`becomingbig` chapter. If you are curious about53the Flask design principles, head over to the section about :doc:`design`.
modified:docs/index.rst+6 added-7 removed
1.. rst-class:: hide-header23.. rst-class:: hide-header43Welcome to Flask4================56.. image:: _static/flask-logo.png7 :alt: Flask: web development, one drop at a time8 :align: center9 :target: https://palletsprojects.com/p/flask/1013Welcome to Flask's documentation. Get started with :ref:`installation`14and then get an overview with the :ref:`quickstart`. There is also a15more detailed :ref:`tutorial` that shows how to create a small but11Welcome to Flask's documentation. Get started with :doc:`installation`12and then get an overview with the :doc:`quickstart`. There is also a13more detailed :doc:`tutorial/index` that shows how to create a small but14complete application with Flask. Common patterns are described in the17:ref:`patterns` section. The rest of the docs describe each component of18Flask in detail, with a full reference in the :ref:`api` section.15:doc:`patterns/index` section. The rest of the docs describe each16component of Flask in detail, with a full reference in the :doc:`api`17section.1819Flask depends on the `Jinja`_ template engine and the `Werkzeug`_ WSGI20toolkit. The documentation for these libraries can be found at:21
68 unmodified lines
modified:docs/installation.rst+3 added-3 removed
1.. _installation:21Installation2============34
32 unmodified lines
3738These distributions will not be installed automatically. Flask will detect and39use them if you install them.4043* `Blinker`_ provides support for :ref:`signals`.41* `Blinker`_ provides support for :doc:`signals`.42* `SimpleJSON`_ is a fast JSON implementation that is compatible with43 Python's ``json`` module. It is preferred for JSON operations if it is44 installed.45* `python-dotenv`_ enables support for :ref:`dotenv` when running ``flask``
25 unmodified lines
71Python comes bundled with the :mod:`venv` module to create virtual72environments.737475.. _install-create-env:7677Create an environment78~~~~~~~~~~~~~~~~~~~~~7980Create a project folder and a :file:`venv` folder within:
47 unmodified lines
modified:docs/license.rst+3 added-3 removed
2 unmodified lines
34Source License5--------------67This license applies to all files in the Flask repository and source8distribution. This includes Flask's source code, the examples, and9tests, as well as the documentation.7The BSD-3-Clause license applies to all files in the Flask repository8and source distribution. This includes Flask's source code, the9examples, and tests, as well as the documentation.1011.. include:: ../LICENSE.rst1213
6 unmodified lines
modified:docs/quickstart.rst+18 added-20 removed
1.. _quickstart:21Quickstart2==========34Eager to get started? This page gives a good introduction to Flask.
53 unmodified lines
58And on PowerShell::5960 PS C:\path\to\app> $env:FLASK_APP = "hello.py"6164This launches a very simple builtin server, which is good enough for testing65but probably not what you want to use in production. For deployment options see66:ref:`deployment`.62This launches a very simple builtin server, which is good enough for63testing but probably not what you want to use in production. For64deployment options see :doc:`deploying/index`.6566Now head over to http://127.0.0.1:5000/, and you should see your hello67world greeting.68
46 unmodified lines
115116Debug Mode117----------118121(Want to just log errors and stack traces? See :ref:`application-errors`)119(Want to just log errors and stack traces? See :doc:`errorhandling`)120121The :command:`flask` script is nice to start a local development server, but122you would have to restart it manually after each change to your code.123That is not very nice and Flask can do better. If you enable debug
305 unmodified lines
429:class:`~flask.session` and :class:`~flask.g` [#]_ objects430as well as the :func:`~flask.get_flashed_messages` function.431432Templates are especially useful if inheritance is used. If you want to435know how that works, head over to the :ref:`template-inheritance` pattern436documentation. Basically template inheritance makes it possible to keep437certain elements on each page (like header, navigation and footer).433know how that works, see :doc:`patterns/templateinheritance`. Basically434template inheritance makes it possible to keep certain elements on each435page (like header, navigation and footer).436437Automatic escaping is enabled, so if ``name`` contains HTML it will be escaped438automatically. If you can trust a variable and you know that it will be439safe HTML (for example because it came from a module that converts wiki
18 unmodified lines
458 ``.xml``, ``.xhtml``. Templates loaded from a string will have459 autoescaping disabled.460461.. [#] Unsure what that :class:`~flask.g` object is? It's something in which464 you can store information for your own needs, check the documentation of465 that object (:class:`~flask.g`) and the :ref:`sqlite3` for more466 information.462 you can store information for your own needs. See the documentation463 for :class:`flask.g` and :doc:`patterns/sqlite3`.464465466Accessing Request Data467----------------------
141 unmodified lines
609 file = request.files['the_file']610 file.save(f"/var/www/uploads/{secure_filename(f.filename)}")611 ...612616For some better examples, checkout the :ref:`uploading-files` pattern.613For some better examples, see :doc:`patterns/fileuploads`.614615Cookies616```````617
31 unmodified lines
649the :meth:`~flask.make_response` function and then modify it.650651Sometimes you might want to set a cookie at a point where the response652object does not exist yet. This is possible by utilizing the656:ref:`deferred-callbacks` pattern.653:doc:`patterns/deferredcallbacks` pattern.654655For this also see :ref:`about-responses`.656657Redirects and Errors
31 unmodified lines
689Note the ``404`` after the :func:`~flask.render_template` call. This690tells Flask that the status code of that page should be 404 which means691not found. By default 200 is assumed which translates to: all went well.692696See :ref:`error-handlers` for more details.693See :doc:`errorhandling` for more details.694695.. _about-responses:696697About Responses
155 unmodified lines
853template to expose the message.854855To flash a message use the :func:`~flask.flash` method, to get hold of the856messages you can use :func:`~flask.get_flashed_messages` which is also860available in the templates. Check out the :ref:`message-flashing-pattern`861for a full example.857available in the templates. See :doc:`patterns/flashing` for a full858example.859860Logging861-------862
20 unmodified lines
883The attached :attr:`~flask.Flask.logger` is a standard logging884:class:`~logging.Logger`, so head over to the official :mod:`logging`885docs for more information.886890Read more on :ref:`application-errors`.887See :doc:`errorhandling`.888889890Hooking in WSGI Middleware891--------------------------892893To add WSGI middleware to your Flask application, wrap the application's
16 unmodified lines
910Extensions are packages that help you accomplish common tasks. For911example, Flask-SQLAlchemy provides SQLAlchemy support that makes it simple912and easy to use with Flask.913916For more on Flask extensions, have a look at :ref:`extensions`.914For more on Flask extensions, see :doc:`extensions`.915916Deploying to a Web Server917-------------------------918921Ready to deploy your new Flask app? Go to :ref:`deployment`.919Ready to deploy your new Flask app? See :doc:`deploying/index`.
modified:docs/reqcontext.rst+1 added-3 removed
1.. currentmodule:: flask23.. _request-context:43The Request Context4===================56The request context keeps track of the request-level data during a
247 unmodified lines
254- The proxy objects cannot fake their type as the actual object types.255 If you want to perform instance checks, you have to do that on the256 object being proxied.257- The reference to the proxied object is needed in some situations,260 such as sending :ref:`signals` or passing data to a background258 such as sending :doc:`signals` or passing data to a background259 thread.260261If you need to access the underlying object that is proxied, use the262:meth:`~werkzeug.local.LocalProxy._get_current_object` method::
3 unmodified lines
modified:docs/security.rst+2 added-2 removed
3 unmodified lines
4Web applications usually face all kinds of security problems and it's very5hard to get everything right. Flask tries to solve a few of these things6for you, but there are a couple more you have to take care of yourself.78.. _xss:8.. _security-xss:910Cross-Site Scripting (XSS)11--------------------------12
87 unmodified lines
100101Why does Flask not do that for you? The ideal place for this to happen is102the form validation framework, which does not exist in Flask.103104.. _json-security:104.. _security-json:105106JSON Security107-------------108
152 unmodified lines
modified:docs/shell.rst+2 added-4 removed
1.. _shell:21Working with the Shell2======================34.. versionadded:: 0.3
15 unmodified lines
20that these functions are not only there for interactive shell usage, but21also for unit testing and other situations that require a faked request22context.2326Generally it's recommended that you read the :ref:`request-context`24Generally it's recommended that you read the :doc:`reqcontext`25chapter of the documentation first.2627Command Line Interface28----------------------
2 unmodified lines
31``flask shell`` command which does a lot of this automatically for you.32For instance the shell is automatically initialized with a loaded33application context.3437For more information see :ref:`cli`.35For more information see :doc:`/cli`.3637Creating a Request Context38--------------------------39
62 unmodified lines
modified:docs/signals.rst+1 added-3 removed
1.. _signals:21Signals2=======34.. versionadded:: 0.6
154 unmodified lines
159160Signals and Flask's Request Context161-----------------------------------162165Signals fully support :ref:`request-context` when receiving signals.163Signals fully support :doc:`reqcontext` when receiving signals.164Context-local variables are consistently available between165:data:`~flask.request_started` and :data:`~flask.request_finished`, so you can166rely on :class:`flask.g` and others as needed. Note the limitations described167in :ref:`signals-sending` and the :data:`~flask.request_tearing_down` signal.
21 unmodified lines
modified:docs/templating.rst+1 added-3 removed
1.. _templates:21Templates2=========34Flask leverages Jinja2 as its template engine. You are obviously free to use
131 unmodified lines
136carry specific meanings in documents on their own you have to replace them137by so called "entities" if you want to use them for text. Not doing so138would not only cause user frustration by the inability to use these139characters in text, but can also lead to security problems. (see142:ref:`xss`)140:ref:`security-xss`)141142Sometimes however you will need to disable autoescaping in templates.143This can be the case if you want to explicitly inject HTML into pages, for144example if they come from a system that generates secure HTML like a
90 unmodified lines
modified:docs/testing.rst+3 added-5 removed
1.. _testing:21Testing Flask Applications2==========================34 **Something that is untested is broken.**
18 unmodified lines
23The Application24---------------2526First, we need an application to test; we will use the application from29the :ref:`tutorial`. If you don't have that application yet, get the30source code from :gh:`the examples <examples/tutorial>`.27the :doc:`tutorial/index`. If you don't have that application yet, get28the source code from :gh:`the examples <examples/tutorial>`.2930So that we can import the module ``flaskr`` correctly, we need to run31``pip install -e .`` in the folder ``tutorial``.32
203 unmodified lines
236way.237238If you want to test your application with different configurations and239there does not seem to be a good way to do that, consider switching to242application factories (see :ref:`app-factories`).240application factories (see :doc:`patterns/appfactories`).241242Note however that if you are using a test request context, the243:meth:`~flask.Flask.before_request` and :meth:`~flask.Flask.after_request`244functions are not called automatically. However
218 unmodified lines
modified:docs/views.rst-2 removed
1.. _views:21Pluggable Views2===============34.. versionadded:: 0.7
231 unmodified lines
modified:src/flask/json/__init__.py+3 added-2 removed
329 unmodified lines
330 }331332333 .. versionchanged:: 0.11334 Added support for serializing top-level arrays. This introduces a335 security risk in ancient browsers. See :ref:`json-security` for details.334 Added support for serializing top-level arrays. This introduces335 a security risk in ancient browsers. See :ref:`security-json`336 for details.337338 This function's response will be pretty printed if the339 ``JSONIFY_PRETTYPRINT_REGULAR`` config parameter is set to True or the340 Flask app is running in debug mode. Compressed (not pretty) formatting
27 unmodified lines
modified:src/flask/app.py+2 added-2 removed
866 unmodified lines
867 """Runs the application on a local development server.868869 Do not use ``run()`` in a production setting. It is not intended to870 meet security and performance requirements for a production server.871 Instead, see :ref:`deployment` for WSGI server recommendations.871 Instead, see :doc:`/deploying/index` for WSGI server recommendations.872873 If the :attr:`debug` flag is set the server will automatically reload874 for code changes and show a debugger in case an exception happened.875
103 unmodified lines
979 self._got_first_request = False980981 def test_client(self, use_cookies=True, **kwargs):982 """Creates a test client for this application. For information983 about unit testing head over to :ref:`testing`.983 about unit testing head over to :doc:`/testing`.984985 Note that if you are testing for assertions or exceptions in your986 application code, you must set ``app.testing = True`` in order for the987 exceptions to propagate to the test client. Otherwise, the exception
1384 unmodified lines
modified:src/flask/blueprints.py+1 added-1 removed
88 unmodified lines
89 Decorating a function with a blueprint creates a deferred function90 that is called with :class:`~flask.blueprints.BlueprintSetupState`91 when the blueprint is registered on an application.9293 See :ref:`blueprints` for more information.93 See :doc:`/blueprints` for more information.9495 .. versionchanged:: 1.1.096 Blueprints have a ``cli`` group to register nested CLI commands.97 The ``cli_group`` parameter controls the name of the group under
461 unmodified lines
modified:src/flask/cli.py+1 added-3 removed
442 unmodified lines
443 """Special subclass of the :class:`AppGroup` group that supports444 loading more commands from the configured Flask app. Normally a445 developer does not have to interface with this class but there are446 some very advanced use cases for which it makes sense to create an447 instance of this.447 instance of this. see :ref:`custom-scripts`.448449 For information as of why this is useful see :ref:`custom-scripts`.450449 :param add_default_commands: if this is True then the default run and450 shell commands will be added.451 :param add_version_option: adds the ``--version`` option.452 :param create_app: an optional callback that is passed the script info and
486 unmodified lines
modified:src/flask/helpers.py+5 added-5 removed
219 unmodified lines
220 This will reference the index function local to the current blueprint::221222 url_for('.index')223224 For more information, head over to the :ref:`Quickstart <url-building>`.224 See :ref:`url-building`.225226 Configuration values ``APPLICATION_ROOT`` and ``SERVER_NAME`` are only used when227 generating URLs outside of a request context.228
48 unmodified lines
277 falls back to the `Host` header, then to the IP and port of the request.278 :param _scheme: a string specifying the desired URL scheme. The `_external`279 parameter must be set to ``True`` or a :exc:`ValueError` is raised. The default280 behavior uses the same scheme as the current request, or281 ``PREFERRED_URL_SCHEME`` from the :ref:`app configuration <config>` if no282 request context is available. As of Werkzeug 0.10, this also can be set283 to an empty string to build protocol-relative URLs.281 :data:`PREFERRED_URL_SCHEME` if no request context is available.282 This also can be set to an empty string to build protocol-relative283 URLs.284 :param _anchor: if provided this is added as anchor to the URL.285 :param _method: if provided this explicitly specifies an HTTP method.286 """287 appctx = _app_ctx_stack.top
139 unmodified lines
427 text (``True`` gives a tuple, where ``False`` gives just the message text).428 * `category_filter` filters the messages down to only those matching the429 provided categories.430431 See :ref:`message-flashing-pattern` for examples.431 See :doc:`/patterns/flashing` for examples.432433 .. versionchanged:: 0.3434 `with_categories` parameter added.435
689 unmodified lines
modified:src/flask/testing.py+1 added-1 removed
92 unmodified lines
93 `app.test_client()` includes preset default environment, which can be94 set after instantiation of the `app.test_client()` object in95 `client.environ_base`.9697 Basic usage is outlined in the :ref:`testing` chapter.97 Basic usage is outlined in the :doc:`/testing` chapter.98 """99100 preserve_context = False101
152 unmodified lines