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
Provenance
- Commit
171aabc- Tree
e62cebb- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
f2f027d
55 files changed+129 added−221 removed
modified:docs/deploying/fastcgi.rst-2 removed
1-.. _deploying-fastcgi:2-1 FastCGI2 =======3 4 FastCGI is a deployment option on servers like `nginx`_, `lighttpd`_, and234 unmodified linesmodified:docs/deploying/index.rst-2 removed
1-.. _deployment:2-1 Deployment Options2 ==================3 4 While lightweight and easy to use, **Flask's built-in server is not suitable29 unmodified linesmodified:docs/deploying/mod_wsgi.rst-2 removed
1-.. _mod_wsgi-deployment:2-1 mod_wsgi (Apache)2 =================3 4 If you are using the `Apache`_ webserver, consider using `mod_wsgi`_.212 unmodified linesmodified:docs/deploying/uwsgi.rst-2 removed
1-.. _deploying-uwsgi:2-1 uWSGI2 =====3 4 uWSGI is a deployment option on servers like `nginx`_, `lighttpd`_, and67 unmodified linesmodified:docs/deploying/wsgi-standalone.rst-2 removed
1-.. _deploying-wsgi-standalone:2-1 Standalone WSGI Containers2 ==========================3 4 There are popular servers written in Python that contain WSGI applications and149 unmodified linesmodified:docs/patterns/appdispatch.rst+10 added-12 removed
1-.. _app-dispatch:2-1 Application Dispatching2 =======================3 4 Application dispatching is the process of combining multiple Flask2 unmodified lines7 Django and a Flask application in the same interpreter side by side if8 you want. The usefulness of this depends on how the applications work9 internally.10 13-The fundamental difference from the :ref:`module approach14-<larger-applications>` is that in this case you are running the same or15-different Flask applications that are entirely isolated from each other.16-They run different configurations and are dispatched on the WSGI level.11+The fundamental difference from :doc:`packages` is that in this case you12+are running the same or different Flask applications that are entirely13+isolated from each other. They run different configurations and are14+dispatched on the WSGI level.15 16 17 Working with this Document18 --------------------------19 22-Each of the techniques and examples below results in an ``application`` object23-that can be run with any WSGI server. For production, see :ref:`deployment`.24-For development, Werkzeug provides a builtin server for development available25-at :func:`werkzeug.serving.run_simple`::20+Each of the techniques and examples below results in an ``application``21+object that can be run with any WSGI server. For production, see22+:doc:`/deploying/index`. For development, Werkzeug provides a server23+through :func:`werkzeug.serving.run_simple`::24 25 from werkzeug.serving import run_simple26 run_simple('localhost', 5000, application, use_reloader=True)27 28 Note that :func:`run_simple <werkzeug.serving.run_simple>` is not intended for31-use in production. Use a :ref:`full-blown WSGI server <deployment>`.29+use in production. Use a production WSGI server. See :doc:`/deploying/index`.30 31 In order to use the interactive debugger, debugging must be enabled both on32 the application and the simple server. Here is the "hello world" example with33 debugging and :func:`run_simple <werkzeug.serving.run_simple>`::42 unmodified lines76 with different configurations. Assuming the application is created inside77 a function and you can call that function to instantiate it, that is78 really easy to implement. In order to develop your application to support79 creating new instances in functions have a look at the82-:ref:`app-factories` pattern.80+:doc:`appfactories` pattern.81 82 A very common example would be creating applications per subdomain. For83 instance you configure your webserver to dispatch all requests for all84 subdomains to your application and you then use the subdomain information102 unmodified linesmodified:docs/patterns/appfactories.rst+1 added-3 removed
1-.. _app-factories:2-1 Application Factories2 =====================3 4 If 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 improve6 the experience. A common pattern is creating the application object when7 the blueprint is imported. But if you move the creation of this object8 into a function, you can then create multiple instances of this app later.9 106 unmodified linesmodified:docs/patterns/caching.rst-2 removed
1-.. _caching-pattern:2-1 Caching2 =======3 4 When your application runs slow, throw some caches in. Well, at least12 unmodified linesmodified:docs/patterns/deferredcallbacks.rst-2 removed
1-.. _deferred-callbacks:2-1 Deferred Request Callbacks2 ==========================3 4 One of the design principles of Flask is that response objects are created and40 unmodified linesmodified:docs/patterns/distribute.rst+6 added-9 removed
1-.. _distribute-deployment:2-1 Deploying with Setuptools2 =========================3 4 `Setuptools`_, is an extension library that is commonly used to15 unmodified lines20 Flask itself, and all the libraries you can find on PyPI are distributed with21 either setuptools or distutils.22 23 In 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 into28-a package, head over to the :ref:`larger-applications` pattern to see29-how this can be done.24+:file:`yourapplication.py` and you are not using a module, but a25+package. If you have not yet converted your application into a package,26+head over to :doc:`packages` to see how this can be done.27 28 A working deployment with setuptools is the first step into more complex29 and more automated deployment scenarios. If you want to fully automate33-the process, also read the :ref:`fabric-deployment` chapter.30+the process, also read the :doc:`fabric` chapter.31 32 Basic Setup Script33 ------------------34 35 Because you have Flask installed, you have setuptools available on your system.36 Flask already depends upon setuptools.37 41-Standard disclaimer applies: :ref:`you better use a virtualenv42-<virtualenv>`.38+Standard disclaimer applies: :ref:`use a virtualenv39+<install-create-env>`.40 41 Your setup code always goes into a file named :file:`setup.py` next to your42 application. The name of the file is only convention, but because43 everybody will look for a file with that name, you better not change it.127 unmodified linesmodified:docs/patterns/errorpages.rst+2 added-4 removed
1-.. _errorpages:2-1 Custom Error Pages2 ==================3 4 Flask comes with a handy :func:`~flask.abort` function that aborts a33 unmodified lines38 *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`).43 44 45 Error Handlers46 --------------24 unmodified lines71 def page_not_found(e):72 # note that we set the 404 status explicitly73 return render_template('404.html'), 40474 77-When using the :ref:`application factory pattern <app-factories>`::75+When using the :doc:`appfactories`::76 77 from flask import Flask, render_template78 79 def page_not_found(e):44 unmodified linesmodified:docs/patterns/fabric.rst+5 added-7 removed
1-.. _fabric-deployment:2-1 Deploying with Fabric2 =====================3 4 `Fabric`_ is a tool for Python similar to Makefiles but with the ability5 to execute commands on a remote server. In combination with a properly8-set up Python package (:ref:`larger-applications`) and a good concept for9-configurations (:ref:`config`) it is very easy to deploy Flask6+set up Python package (:doc:`packages`) and a good concept for7+configurations (:doc:`/config`) it is very easy to deploy Flask8 applications to external servers.9 10 Before we get started, here a quick checklist of things we have to ensure11 upfront:12 13 - 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 root77 unmodified lines98 99 3. 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`.103 104 So now the question is, where do the :file:`application.wsgi` and105 :file:`application.cfg` files come from?106 14 unmodified lines121 app = Flask(__name__)122 app.config.from_object('yourapplication.default_config')123 app.config.from_envvar('YOURAPPLICATION_CONFIG')124 127-This approach is explained in detail in the :ref:`config` section of the125+This approach is explained in detail in the :doc:`/config` section of the126 documentation.127 128 The Configuration File129 ----------------------55 unmodified linesmodified:docs/patterns/fileuploads.rst+1 added-3 removed
1-.. _uploading-files:2-1 Uploading Files2 ===============3 4 Ah yes, the good old problem of file uploads. The basic idea of file31 unmodified lines36 Why do we limit the extensions that are allowed? You probably don't want37 your users to be able to upload everything there if the server is directly38 sending out the data to the client. That way you can make sure that users39 are 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 server41 executes them, but who has PHP installed on their server, right? :)42 43 Next the functions that check if an extension is valid and that uploads44 the file and redirects the user to the URL for the uploaded file::144 unmodified linesmodified:docs/patterns/flashing.rst-2 removed
1-.. _message-flashing-pattern:2-1 Message Flashing2 ================3 4 Good applications and user interfaces are all about feedback. If the user144 unmodified linesmodified:docs/patterns/index.rst-2 removed
1-.. _patterns:2-1 Patterns for Flask2 ==================3 4 Certain features and interactions are common enough that you will find40 unmodified linesdeleted:docs/patterns/mongokit.rst-7 removed
1-:orphan:2-3-MongoDB with MongoKit4-=====================5-6-MongoKit is no longer maintained. See :doc:`/patterns/mongoengine`7-instead.modified:docs/patterns/packages.rst+5 added-9 removed
1-.. _larger-applications:1+Large Applications as Packages2+==============================3 3-Larger Applications4-===================5-4 Imagine a simple flask application structure that looks like this::5 6 /yourapplication7 yourapplication.py6 unmodified lines14 ...15 16 While this is fine for small applications, for larger applications17 it's a good idea to use a package instead of a module.20-The :ref:`tutorial <tutorial>` is structured to use the package pattern,18+The :doc:`/tutorial/index` is structured to use the package pattern,19 see the :gh:`example code <examples/tutorial>`.20 21 Simple Packages22 ---------------103 unmodified lines126 the file.127 128 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.131 132 135-.. _working-with-modules:136-133 Working with Blueprints134 -----------------------135 136 If you have larger applications it's recommended to divide them into137 smaller groups where each group is implemented with the help of a138 blueprint. 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:2-1 SQLAlchemy in Flask2 ===================3 4 Many people prefer `SQLAlchemy`_ for database access. In this case it's5 encouraged to use a package instead of a module for your flask application8-and drop the models into a separate module (:ref:`larger-applications`).9-While that is not necessary, it makes a lot of sense.6+and drop the models into a separate module (:doc:`packages`). While that7+is not necessary, it makes a lot of sense.8 9 There are four very common ways to use SQLAlchemy. I will outline each10 of them here:11 94 unmodified lines106 >>> User.query.filter(User.name == 'admin').first()107 <User 'admin'>108 109 .. _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/111 112 Manual Object Relational Mapping113 --------------------------------114 101 unmodified linesmodified:docs/patterns/sqlite3.rst-3 removed
1-.. _sqlite3:2-1 Using SQLite 3 with Flask2 =========================3 4 In Flask you can easily implement the opening of database connections on54 unmodified lines59 60 with app.app_context():61 # now you can use get_db()62 65-.. _easy-querying:63 64 Easy Querying65 -------------66 85 unmodified linesmodified:docs/patterns/templateinheritance.rst-2 removed
1-.. _template-inheritance:2-1 Template Inheritance2 ====================3 4 The most powerful part of Jinja is template inheritance. Template inheritance64 unmodified linesmodified:docs/patterns/viewdecorators.rst+3 added-3 removed
57 unmodified lines58 59 Imagine you have a view function that does an expensive calculation and60 because of that you would like to cache the generated results for a61 certain amount of time. A decorator would be nice for that. We're62-assuming you have set up a cache like mentioned in :ref:`caching-pattern`.62+assuming you have set up a cache like mentioned in :doc:`caching`.63 64 Here is an example cache function. It generates the cache key from a65 specific prefix (actually a format string) and the current path of the66 request. Notice that we are using a function that first creates the28 unmodified lines95 return rv96 return decorated_function97 return decorator98 99-Notice that this assumes an instantiated `cache` object is available, see100-:ref:`caching-pattern` for more information.99+Notice that this assumes an instantiated ``cache`` object is available, see100+:doc:`caching`.101 102 103 Templating Decorator104 --------------------67 unmodified linesmodified:docs/patterns/wtforms.rst+2 added-2 removed
7 unmodified lines8 forms, you might want to give it a try.9 10 When you are working with WTForms you have to define your forms as classes11 first. 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 the13 forms.14 15 .. admonition:: Getting the most out of WTForms with an Extension16 37 unmodified lines54 return redirect(url_for('login'))55 return render_template('register.html', form=form)56 57 Notice 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. Adapt59 the code as necessary.60 61 Things to remember:62 64 unmodified linesmodified:docs/tutorial/database.rst+4 added-4 removed
140 unmodified lines141 read from the file.142 143 :func:`click.command` defines a command line command called ``init-db``144 that calls the ``init_db`` function and shows a success message to the145-user. You can read :ref:`cli` to learn more about writing commands.145+user. You can read :doc:`/cli` to learn more about writing commands.146 147 148 Register with the Application149 -----------------------------45 unmodified lines195 196 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.202 203 Run the ``init-db`` command:204 205 .. code-block:: none8 unmodified linesmodified:docs/tutorial/index.rst+3 added-5 removed
1-.. _tutorial:2-1 Tutorial2 ========3 4 .. toctree::27 unmodified lines32 33 .. _official tutorial: https://docs.python.org/3/tutorial/34 35 While it's designed to give a good starting point, the tutorial doesn't38-cover all of Flask's features. Check out the :ref:`quickstart` for an36+cover all of Flask's features. Check out the :doc:`/quickstart` for an37 overview of what Flask can do, then dive into the docs to find out more.38 The tutorial only uses what's provided by Flask and Python. In another41-project, you might decide to use :ref:`extensions` or other libraries to42-make some tasks simpler.39+project, you might decide to use :doc:`/extensions` or other libraries40+to make some tasks simpler.41 42 .. image:: flaskr_login.png43 :align: center44 :class: screenshot20 unmodified linesmodified:docs/tutorial/next.rst+2 added-2 removed
7 unmodified lines8 different due to the step-by-step nature of the tutorial.9 10 There's a lot more to Flask than what you've seen so far. Even so,11 you're now equipped to start developing your own web applications. Check12-out the :ref:`quickstart` for an overview of what Flask can do, then12+out the :doc:`/quickstart` for an overview of what Flask can do, then13 dive into the docs to keep learning. Flask uses `Jinja`_, `Click`_,14 `Werkzeug`_, and `ItsDangerous`_ behind the scenes, and they all have15 their 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 or17 validating form data easier and more powerful.18 19 If you want to keep developing your Flaskr project, here are some ideas20 for what to try next:18 unmodified linesmodified:docs/advanced_foreword.rst-2 removed
1-.. _advanced_foreword:2-1 Foreword for Experienced Programmers2 ====================================3 4 Thread-Locals in Flask42 unmodified linesmodified:docs/api.rst+4 added-8 removed
1-.. _api:2-1 API2 ===3 4 .. module:: flask318 unmodified lines323 </script>324 325 .. admonition:: Auto-Sort JSON Keys326 329- 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.330 333- 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.333 334 .. autofunction:: jsonify335 336 .. autofunction:: dumps294 unmodified lines631 632 633 .. _blinker: https://pypi.org/project/blinker/634 637-.. _class-based-views:635 636 Class-Based Views637 -----------------638 118 unmodified lines757 implicitly added and handled by the standard request758 handling. They have to be specified as keyword arguments.759 =============== ==========================================================760 764-.. _view-func-options:761 762 View Function Options763 ---------------------764 66 unmodified linesmodified:docs/appcontext.rst-2 removed
1 .. currentmodule:: flask2 3-.. _app-context:4-3 The Application Context4 =======================5 6 The application context keeps track of the application-level data during151 unmodified linesmodified:docs/becomingbig.rst+4 added-6 removed
1-.. _becomingbig:2-1 Becoming Big2 ============3 4 Here are your options when growing your codebase or scaling your application.12 unmodified lines17 18 Hook. Extend.19 -------------20 23-The :ref:`api` docs are full of available overrides, hook points, and24-:ref:`signals`. You can provide custom classes for things like the21+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 many5 unmodified lines32 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 an38-application class. This works well with :ref:`app-factories`.36+application class. This works well with :doc:`/patterns/appfactories`.37 See :doc:`/patterns/subclassing` for an example.38 39 Wrap with middleware.40 ---------------------41 44-The :ref:`app-dispatch` chapter shows in detail how to apply middleware. You42+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/>`_.54 unmodified linesmodified:docs/blueprints.rst+4 added-5 removed
1-.. _blueprints:2-1 Modular Applications with Blueprints2 ====================================3 4 .. currentmodule:: flask29 unmodified lines34 35 A blueprint in Flask is not a pluggable app because it is not actually an36 application -- it's a set of operations which can be registered on an37 application, even multiple times. Why not have multiple application40-objects? You can do that (see :ref:`app-dispatch`), but your applications41-will have separate configs and will be managed at the WSGI layer.38+objects? You can do that (see :doc:`/patterns/appdispatch`), but your39+applications will have separate configs and will be managed at the WSGI40+layer.41 42 Blueprints instead provide separation at the Flask level, share43 application config, and can change an application object as necessary with44 being registered. The downside is that you cannot unregister a blueprint227 unmodified lines272 return jsonify_error(ex)273 else:274 return ex275 277-More information on error handling see :ref:`errorpages`.276+More information on error handling see :doc:`/patterns/errorpages`.modified:docs/changelog.rst+2 added-2 removed
1-Changelog2-=========1+Changes2+=======3 4 .. include:: ../CHANGES.rstmodified:docs/cli.rst+1 added-3 removed
1 .. currentmodule:: flask2 3-.. _cli:4-3 Command Line Interface4 ======================5 6 Installing Flask installs the ``flask`` script, a `Click`_ command line89 unmodified lines96 97 .. 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.101 102 103 Open a Shell104 ------------437 unmodified linesmodified:docs/config.rst+3 added-5 removed
1-.. _config:2-1 Configuration Handling2 ======================3 4 Applications need some kind of configuration. There are different settings270 unmodified lines275 276 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).281 282 Will be used for the session cookie path if ``SESSION_COOKIE_PATH`` is not283 set.112 unmodified lines396 397 Configuration becomes more useful if you can store it in a separate file,398 ideally located outside the actual application package. This makes399 packaging and distributing your application possible via various package402-handling tools (:ref:`distribute-deployment`) and finally modifying the400+handling tools (:doc:`/patterns/distribute`) and finally modifying the401 configuration file afterwards.402 403 So a common pattern is this::404 220 unmodified lines625 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.630 631 .. _fabric: https://www.fabfile.org/632 633 82 unmodified linesmodified:docs/design.rst+2 added-4 removed
1-.. _design:2-1 Design Decisions in Flask2 =========================3 4 If you are curious why Flask does certain things the way it does and not69 unmodified lines74 to the application object :meth:`~flask.Flask.wsgi_app`).75 76 Furthermore this design makes it possible to use a factory function to77 create the application which is very helpful for unit testing and similar80-things (:ref:`app-factories`).78+things (:doc:`/patterns/appfactories`).79 80 The Routing System81 ------------------82 83 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 172-Also see the :ref:`becomingbig` section of the documentation for some170+Also see the :doc:`/becomingbig` section of the documentation for some171 inspiration for larger applications based on Flask.172 173 174 What Flask is, What Flask is Not15 unmodified linesmodified:docs/errorhandling.rst+1 added-4 removed
1-.. _application-errors:2-1 Application Errors2 ==================3 4 .. versionadded:: 0.360 unmodified lines65 <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/>`_.68 71-.. _error-handlers:69 70 Error handlers71 --------------72 162 unmodified lines235 Debugging Application Errors236 ============================237 238 For production applications, configure your application with logging and242-notifications as described in :ref:`application-errors`. This section provides239+notifications as described in :doc:`/logging`. This section provides240 pointers when debugging deployment configuration and digging deeper with a241 full-featured Python debugger.242 243 51 unmodified linesmodified:docs/extensiondev.rst+6 added-5 removed
25 unmodified lines26 27 But what do extensions look like themselves? An extension has to ensure28 that it works with multiple Flask application instances at once. This is29 a requirement because many people will use patterns like the30-:ref:`app-factories` pattern to create their application as needed to aid31-unittests and to support multiple configurations. Because of that it is32-crucial that your application supports that kind of behavior.30+:doc:`/patterns/appfactories` pattern to create their application as31+needed to aid unittests and to support multiple configurations. Because32+of that it is crucial that your application supports that kind of33+behavior.34 35 Most importantly the extension must be shipped with a :file:`setup.py` file and36 registered on PyPI. Also the development checkout link should work so37 that people can easily install the development version into their79 unmodified lines117 -----------------------118 119 Many extensions will need some kind of initialization step. For example,120 consider an application that's currently connecting to SQLite like the120-documentation suggests (:ref:`sqlite3`). So how does the extension121-know the name of the application object?121+documentation suggests (:doc:`/patterns/sqlite3`). So how does the122+extension know the name of the application object?123 124 Quite simple: you pass it to it.125 126 There are two recommended ways for an extension to initialize:210 unmodified linesmodified:docs/extensions.rst-2 removed
1-.. _extensions:2-1 Extensions2 ==========3 4 Extensions are extra packages that add functionality to a Flask44 unmodified linesmodified:docs/foreword.rst+2 added-5 removed
47 unmodified lines48 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 :ref:`becomingbig` chapter. If you are curious about53-the Flask design principles, head over to the section about :ref:`design`.54-55-Continue to :ref:`installation`, the :ref:`quickstart`, or the56-:ref:`advanced_foreword`.52+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`.modified:docs/index.rst+6 added-7 removed
1 .. rst-class:: hide-header2 3-.. rst-class:: hide-header4-3 Welcome to Flask4 ================5 6 .. image:: _static/flask-logo.png7 :alt: Flask: web development, one drop at a time8 :align: center9 :target: https://palletsprojects.com/p/flask/10 13-Welcome to Flask's documentation. Get started with :ref:`installation`14-and then get an overview with the :ref:`quickstart`. There is also a15-more detailed :ref:`tutorial` that shows how to create a small but11+Welcome to Flask's documentation. Get started with :doc:`installation`12+and then get an overview with the :doc:`quickstart`. There is also a13+more detailed :doc:`tutorial/index` that shows how to create a small but14 complete application with Flask. Common patterns are described in the17-:ref:`patterns` section. The rest of the docs describe each component of18-Flask in detail, with a full reference in the :ref:`api` section.15+:doc:`patterns/index` section. The rest of the docs describe each16+component of Flask in detail, with a full reference in the :doc:`api`17+section.18 19 Flask depends on the `Jinja`_ template engine and the `Werkzeug`_ WSGI20 toolkit. The documentation for these libraries can be found at:21 68 unmodified linesmodified:docs/installation.rst+3 added-3 removed
1-.. _installation:2-1 Installation2 ============3 4 32 unmodified lines37 38 These distributions will not be installed automatically. Flask will detect and39 use them if you install them.40 43-* `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 lines71 Python comes bundled with the :mod:`venv` module to create virtual72 environments.73 74 75+.. _install-create-env:76+77 Create an environment78 ~~~~~~~~~~~~~~~~~~~~~79 80 Create a project folder and a :file:`venv` folder within:47 unmodified linesmodified:docs/license.rst+3 added-3 removed
2 unmodified lines3 4 Source License5 --------------6 7-This license applies to all files in the Flask repository and source8-distribution. This includes Flask's source code, the examples, and9-tests, as well as the documentation.7+The BSD-3-Clause license applies to all files in the Flask repository8+and source distribution. This includes Flask's source code, the9+examples, and tests, as well as the documentation.10 11 .. include:: ../LICENSE.rst12 13 6 unmodified linesmodified:docs/quickstart.rst+18 added-20 removed
1-.. _quickstart:2-1 Quickstart2 ==========3 4 Eager to get started? This page gives a good introduction to Flask.53 unmodified lines58 And on PowerShell::59 60 PS C:\path\to\app> $env:FLASK_APP = "hello.py"61 64-This launches a very simple builtin server, which is good enough for testing65-but probably not what you want to use in production. For deployment options see66-:ref:`deployment`.62+This launches a very simple builtin server, which is good enough for63+testing but probably not what you want to use in production. For64+deployment options see :doc:`deploying/index`.65 66 Now head over to http://127.0.0.1:5000/, and you should see your hello67 world greeting.68 46 unmodified lines115 116 Debug Mode117 ----------118 121-(Want to just log errors and stack traces? See :ref:`application-errors`)119+(Want to just log errors and stack traces? See :doc:`errorhandling`)120 121 The :command:`flask` script is nice to start a local development server, but122 you would have to restart it manually after each change to your code.123 That is not very nice and Flask can do better. If you enable debug305 unmodified lines429 :class:`~flask.session` and :class:`~flask.g` [#]_ objects430 as well as the :func:`~flask.get_flashed_messages` function.431 432 Templates are especially useful if inheritance is used. If you want to435-know how that works, head over to the :ref:`template-inheritance` pattern436-documentation. Basically template inheritance makes it possible to keep437-certain elements on each page (like header, navigation and footer).433+know how that works, see :doc:`patterns/templateinheritance`. Basically434+template inheritance makes it possible to keep certain elements on each435+page (like header, navigation and footer).436 437 Automatic escaping is enabled, so if ``name`` contains HTML it will be escaped438 automatically. If you can trust a variable and you know that it will be439 safe HTML (for example because it came from a module that converts wiki18 unmodified lines458 ``.xml``, ``.xhtml``. Templates loaded from a string will have459 autoescaping disabled.460 461 .. [#] 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`.464 465 466 Accessing Request Data467 ----------------------141 unmodified lines609 file = request.files['the_file']610 file.save(f"/var/www/uploads/{secure_filename(f.filename)}")611 ...612 616-For some better examples, checkout the :ref:`uploading-files` pattern.613+For some better examples, see :doc:`patterns/fileuploads`.614 615 Cookies616 ```````617 31 unmodified lines649 the :meth:`~flask.make_response` function and then modify it.650 651 Sometimes you might want to set a cookie at a point where the response652 object does not exist yet. This is possible by utilizing the656-:ref:`deferred-callbacks` pattern.653+:doc:`patterns/deferredcallbacks` pattern.654 655 For this also see :ref:`about-responses`.656 657 Redirects and Errors31 unmodified lines689 Note the ``404`` after the :func:`~flask.render_template` call. This690 tells Flask that the status code of that page should be 404 which means691 not found. By default 200 is assumed which translates to: all went well.692 696-See :ref:`error-handlers` for more details.693+See :doc:`errorhandling` for more details.694 695 .. _about-responses:696 697 About Responses155 unmodified lines853 template to expose the message.854 855 To flash a message use the :func:`~flask.flash` method, to get hold of the856 messages you can use :func:`~flask.get_flashed_messages` which is also860-available in the templates. Check out the :ref:`message-flashing-pattern`861-for a full example.857+available in the templates. See :doc:`patterns/flashing` for a full858+example.859 860 Logging861 -------862 20 unmodified lines883 The attached :attr:`~flask.Flask.logger` is a standard logging884 :class:`~logging.Logger`, so head over to the official :mod:`logging`885 docs for more information.886 890-Read more on :ref:`application-errors`.887+See :doc:`errorhandling`.888 889+890 Hooking in WSGI Middleware891 --------------------------892 893 To add WSGI middleware to your Flask application, wrap the application's16 unmodified lines910 Extensions are packages that help you accomplish common tasks. For911 example, Flask-SQLAlchemy provides SQLAlchemy support that makes it simple912 and easy to use with Flask.913 916-For more on Flask extensions, have a look at :ref:`extensions`.914+For more on Flask extensions, see :doc:`extensions`.915 916 Deploying to a Web Server917 -------------------------918 921-Ready to deploy your new Flask app? Go to :ref:`deployment`.919+Ready to deploy your new Flask app? See :doc:`deploying/index`.modified:docs/reqcontext.rst+1 added-3 removed
1 .. currentmodule:: flask2 3-.. _request-context:4-3 The Request Context4 ===================5 6 The request context keeps track of the request-level data during a247 unmodified lines254 - 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.260 261 If you need to access the underlying object that is proxied, use the262 :meth:`~werkzeug.local.LocalProxy._get_current_object` method::3 unmodified linesmodified:docs/security.rst+2 added-2 removed
3 unmodified lines4 Web applications usually face all kinds of security problems and it's very5 hard to get everything right. Flask tries to solve a few of these things6 for you, but there are a couple more you have to take care of yourself.7 8-.. _xss:8+.. _security-xss:9 10 Cross-Site Scripting (XSS)11 --------------------------12 87 unmodified lines100 101 Why does Flask not do that for you? The ideal place for this to happen is102 the form validation framework, which does not exist in Flask.103 104-.. _json-security:104+.. _security-json:105 106 JSON Security107 -------------108 152 unmodified linesmodified:docs/shell.rst+2 added-4 removed
1-.. _shell:2-1 Working with the Shell2 ======================3 4 .. versionadded:: 0.315 unmodified lines20 that these functions are not only there for interactive shell usage, but21 also for unit testing and other situations that require a faked request22 context.23 26-Generally it's recommended that you read the :ref:`request-context`24+Generally it's recommended that you read the :doc:`reqcontext`25 chapter of the documentation first.26 27 Command Line Interface28 ----------------------2 unmodified lines31 ``flask shell`` command which does a lot of this automatically for you.32 For instance the shell is automatically initialized with a loaded33 application context.34 37-For more information see :ref:`cli`.35+For more information see :doc:`/cli`.36 37 Creating a Request Context38 --------------------------39 62 unmodified linesmodified:docs/signals.rst+1 added-3 removed
1-.. _signals:2-1 Signals2 =======3 4 .. versionadded:: 0.6154 unmodified lines159 160 Signals and Flask's Request Context161 -----------------------------------162 165-Signals fully support :ref:`request-context` when receiving signals.163+Signals fully support :doc:`reqcontext` when receiving signals.164 Context-local variables are consistently available between165 :data:`~flask.request_started` and :data:`~flask.request_finished`, so you can166 rely on :class:`flask.g` and others as needed. Note the limitations described167 in :ref:`signals-sending` and the :data:`~flask.request_tearing_down` signal.21 unmodified linesmodified:docs/templating.rst+1 added-3 removed
1-.. _templates:2-1 Templates2 =========3 4 Flask leverages Jinja2 as its template engine. You are obviously free to use131 unmodified lines136 carry specific meanings in documents on their own you have to replace them137 by so called "entities" if you want to use them for text. Not doing so138 would not only cause user frustration by the inability to use these139 characters in text, but can also lead to security problems. (see142-:ref:`xss`)140+:ref:`security-xss`)141 142 Sometimes however you will need to disable autoescaping in templates.143 This can be the case if you want to explicitly inject HTML into pages, for144 example if they come from a system that generates secure HTML like a90 unmodified linesmodified:docs/testing.rst+3 added-5 removed
1-.. _testing:2-1 Testing Flask Applications2 ==========================3 4 **Something that is untested is broken.**18 unmodified lines23 The Application24 ---------------25 26 First, we need an application to test; we will use the application from29-the :ref:`tutorial`. If you don't have that application yet, get the30-source code from :gh:`the examples <examples/tutorial>`.27+the :doc:`tutorial/index`. If you don't have that application yet, get28+the source code from :gh:`the examples <examples/tutorial>`.29 30 So that we can import the module ``flaskr`` correctly, we need to run31 ``pip install -e .`` in the folder ``tutorial``.32 203 unmodified lines236 way.237 238 If you want to test your application with different configurations and239 there does not seem to be a good way to do that, consider switching to242-application factories (see :ref:`app-factories`).240+application factories (see :doc:`patterns/appfactories`).241 242 Note however that if you are using a test request context, the243 :meth:`~flask.Flask.before_request` and :meth:`~flask.Flask.after_request`244 functions are not called automatically. However218 unmodified linesmodified:docs/views.rst-2 removed
1-.. _views:2-1 Pluggable Views2 ===============3 4 .. versionadded:: 0.7231 unmodified linesmodified:src/flask/json/__init__.py+3 added-2 removed
329 unmodified lines330 }331 332 333 .. 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.337 338 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) formatting27 unmodified linesmodified:src/flask/app.py+2 added-2 removed
866 unmodified lines867 """Runs the application on a local development server.868 869 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.872 873 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 lines979 self._got_first_request = False980 981 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`.984 985 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 exception1384 unmodified linesmodified:src/flask/blueprints.py+1 added-1 removed
88 unmodified lines89 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.92 93- See :ref:`blueprints` for more information.93+ See :doc:`/blueprints` for more information.94 95 .. 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 under461 unmodified linesmodified:src/flask/cli.py+1 added-3 removed
442 unmodified lines443 """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`.448 449- For information as of why this is useful see :ref:`custom-scripts`.450-449 :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 and486 unmodified linesmodified:src/flask/helpers.py+5 added-5 removed
219 unmodified lines220 This will reference the index function local to the current blueprint::221 222 url_for('.index')223 224- For more information, head over to the :ref:`Quickstart <url-building>`.224+ See :ref:`url-building`.225 226 Configuration values ``APPLICATION_ROOT`` and ``SERVER_NAME`` are only used when227 generating URLs outside of a request context.228 48 unmodified lines277 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.top139 unmodified lines427 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.430 431- See :ref:`message-flashing-pattern` for examples.431+ See :doc:`/patterns/flashing` for examples.432 433 .. versionchanged:: 0.3434 `with_categories` parameter added.435 689 unmodified linesmodified:src/flask/testing.py+1 added-1 removed
92 unmodified lines93 `app.test_client()` includes preset default environment, which can be94 set after instantiation of the `app.test_client()` object in95 `client.environ_base`.96 97- Basic usage is outlined in the :ref:`testing` chapter.97+ Basic usage is outlined in the :doc:`/testing` chapter.98 """99 100 preserve_context = False101 152 unmodified lines