Merge branch '2.2.x'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parents 795d3e2, e3eaafb · Browse files · 11 files·+44 added−682 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+44 added−682 removed
- other:+44 added−682 removed
Provenance
- Commit
87584e8- Tree
8c91499- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
795d3e2- Parent 2
e3eaafb
11 files changed+44 added−682 removed
deleted:docs/patterns/distribute.rst-170 removed
1-Deploying with Setuptools2-=========================3-4-`Setuptools`_, is an extension library that is commonly used to5-distribute Python libraries and extensions. It extends distutils, a basic6-module installation system shipped with Python to also support various more7-complex constructs that make larger applications easier to distribute:8-9-- **support for dependencies**: a library or application can declare a10- list of other libraries it depends on which will be installed11- automatically for you.12-- **package registry**: setuptools registers your package with your13- Python installation. This makes it possible to query information14- provided by one package from another package. The best known feature of15- this system is the entry point support which allows one package to16- declare an "entry point" that another package can hook into to extend the17- other package.18-- **installation manager**: :command:`pip` can install other libraries for you.19-20-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 called24-: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 automate30-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-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.44-45-A basic :file:`setup.py` file for a Flask application looks like this::46-47- from setuptools import setup48-49- setup(50- name='Your Application',51- version='1.0',52- long_description=__doc__,53- packages=['yourapplication'],54- include_package_data=True,55- zip_safe=False,56- install_requires=['Flask']57- )58-59-Please keep in mind that you have to list subpackages explicitly. If you60-want setuptools to lookup the packages for you automatically, you can use61-the ``find_packages`` function::62-63- from setuptools import setup, find_packages64-65- setup(66- ...67- packages=find_packages()68- )69-70-Most parameters to the ``setup`` function should be self explanatory,71-``include_package_data`` and ``zip_safe`` might not be.72-``include_package_data`` tells setuptools to look for a :file:`MANIFEST.in` file73-and install all the entries that match as package data. We will use this74-to distribute the static files and templates along with the Python module75-(see :ref:`distributing-resources`). The ``zip_safe`` flag can be used to76-force or prevent zip Archive creation. In general you probably don't want77-your packages to be installed as zip files because some tools do not78-support them and they make debugging a lot harder.79-80-81-Tagging Builds82---------------83-84-It is useful to distinguish between release and development builds. Add a85-:file:`setup.cfg` file to configure these options. ::86-87- [egg_info]88- tag_build = .dev89- tag_date = 190-91- [aliases]92- release = egg_info -Db ''93-94-Running ``python setup.py sdist`` will create a development package95-with ".dev" and the current date appended: ``flaskr-1.0.dev20160314.tar.gz``.96-Running ``python setup.py release sdist`` will create a release package97-with only the version: ``flaskr-1.0.tar.gz``.98-99-100-.. _distributing-resources:101-102-Distributing Resources103-----------------------104-105-If you try to install the package you just created, you will notice that106-folders like :file:`static` or :file:`templates` are not installed for you. The107-reason for this is that setuptools does not know which files to add for108-you. What you should do, is to create a :file:`MANIFEST.in` file next to your109-:file:`setup.py` file. This file lists all the files that should be added to110-your tarball::111-112- recursive-include yourapplication/templates *113- recursive-include yourapplication/static *114-115-Don't forget that even if you enlist them in your :file:`MANIFEST.in` file, they116-won't be installed for you unless you set the `include_package_data`117-parameter of the ``setup`` function to ``True``!118-119-120-Declaring Dependencies121-----------------------122-123-Dependencies are declared in the ``install_requires`` parameter as a list.124-Each item in that list is the name of a package that should be pulled from125-PyPI on installation. By default it will always use the most recent126-version, but you can also provide minimum and maximum version127-requirements. Here some examples::128-129- install_requires=[130- 'Flask>=0.2',131- 'SQLAlchemy>=0.6',132- 'BrokenPackage>=0.7,<=1.0'133- ]134-135-As mentioned earlier, dependencies are pulled from PyPI. What if you136-want to depend on a package that cannot be found on PyPI and won't be137-because it is an internal package you don't want to share with anyone?138-Just do it as if there was a PyPI entry and provide a list of139-alternative locations where setuptools should look for tarballs::140-141- dependency_links=['http://example.com/yourfiles']142-143-Make sure that page has a directory listing and the links on the page are144-pointing to the actual tarballs with their correct filenames as this is145-how setuptools will find the files. If you have an internal company146-server that contains the packages, provide the URL to that server.147-148-149-Installing / Developing150------------------------151-152-To install your application (ideally into a virtualenv) just run the153-:file:`setup.py` script with the ``install`` parameter. It will install your154-application into the virtualenv's site-packages folder and also download155-and install all dependencies::156-157- $ python setup.py install158-159-If you are developing on the package and also want the requirements to be160-installed, you can use the ``develop`` command instead::161-162- $ python setup.py develop163-164-This has the advantage of just installing a link to the site-packages165-folder instead of copying the data over. You can then continue to work on166-the code without having to run ``install`` again after each change.167-168-169-.. _pip: https://pypi.org/project/pip/170-.. _Setuptools: https://pypi.org/project/setuptools/deleted:docs/patterns/fabric.rst-184 removed
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 properly6-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 working16- :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 root21- access.22-23-Creating the first Fabfile24---------------------------25-26-A fabfile is what controls what Fabric executes. It is named :file:`fabfile.py`27-and executed by the `fab` command. All the functions defined in that file28-will show up as `fab` subcommands. They are executed on one or more29-hosts. These hosts can be defined either in the fabfile or on the command30-line. In this case we will add them to the fabfile.31-32-This is a basic first example that has the ability to upload the current33-source code to the server and install it into a pre-existing34-virtual environment::35-36- from fabric.api import *37-38- # the user to use for the remote commands39- env.user = 'appuser'40- # the servers where the commands are executed41- env.hosts = ['server1.example.com', 'server2.example.com']42-43- def pack():44- # build the package45- local('python setup.py sdist --formats=gztar', capture=False)46-47- def deploy():48- # figure out the package name and version49- dist = local('python setup.py --fullname', capture=True).strip()50- filename = f'{dist}.tar.gz'51-52- # upload the package to the temporary folder on the server53- put(f'dist/{filename}', f'/tmp/{filename}')54-55- # install the package in the application's virtualenv with pip56- run(f'/var/www/yourapplication/env/bin/pip install /tmp/{filename}')57-58- # remove the uploaded package59- run(f'rm -r /tmp/{filename}')60-61- # touch the .wsgi file to trigger a reload in mod_wsgi62- run('touch /var/www/yourapplication.wsgi')63-64-Running Fabfiles65-----------------66-67-Now how do you execute that fabfile? You use the `fab` command. To68-deploy the current version of the code on the remote server you would use69-this command::70-71- $ fab pack deploy72-73-However this requires that our server already has the74-:file:`/var/www/yourapplication` folder created and75-:file:`/var/www/yourapplication/env` to be a virtual environment. Furthermore76-are we not creating the configuration or ``.wsgi`` file on the server. So77-how do we bootstrap a new server into our infrastructure?78-79-This now depends on the number of servers we want to set up. If we just80-have one application server (which the majority of applications will81-have), creating a command in the fabfile for this is overkill. But82-obviously you can do that. In that case you would probably call it83-`setup` or `bootstrap` and then pass the servername explicitly on the84-command line::85-86- $ fab -H newserver.example.com bootstrap87-88-To setup a new server you would roughly do these steps:89-90-1. Create the directory structure in :file:`/var/www`::91-92- $ mkdir /var/www/yourapplication93- $ cd /var/www/yourapplication94- $ virtualenv --distribute env95-96-2. Upload a new :file:`application.wsgi` file to the server and the97- configuration file for the application (eg: :file:`application.cfg`)98-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.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-107-The WSGI File108--------------109-110-The WSGI file has to import the application and also to set an environment111-variable so that the application knows where to look for the config. This112-is a short example that does exactly that::113-114- import os115- os.environ['YOURAPPLICATION_CONFIG'] = '/var/www/yourapplication/application.cfg'116- from yourapplication import app117-118-The application itself then has to initialize itself like this to look for119-the config at that environment variable::120-121- app = Flask(__name__)122- app.config.from_object('yourapplication.default_config')123- app.config.from_envvar('YOURAPPLICATION_CONFIG')124-125-This approach is explained in detail in the :doc:`/config` section of the126-documentation.127-128-The Configuration File129-----------------------130-131-Now as mentioned above, the application will find the correct132-configuration file by looking up the ``YOURAPPLICATION_CONFIG`` environment133-variable. So we have to put the configuration in a place where the134-application will able to find it. Configuration files have the unfriendly135-quality of being different on all computers, so you do not version them136-usually.137-138-A popular approach is to store configuration files for different servers139-in a separate version control repository and check them out on all140-servers. Then symlink the file that is active for the server into the141-location where it's expected (eg: :file:`/var/www/yourapplication`).142-143-Either way, in our case here we only expect one or two servers and we can144-upload them ahead of time by hand.145-146-147-First Deployment148-----------------149-150-Now we can do our first deployment. We have set up the servers so that151-they have their virtual environments and activated apache configs. Now we152-can pack up the application and deploy it::153-154- $ fab pack deploy155-156-Fabric will now connect to all servers and run the commands as written157-down in the fabfile. First it will execute pack so that we have our158-tarball ready and then it will execute deploy and upload the source code159-to all servers and install it there. Thanks to the :file:`setup.py` file we160-will automatically pull in the required libraries into our virtual161-environment.162-163-Next Steps164-----------165-166-From that point onwards there is so much that can be done to make167-deployment actually fun:168-169-- Create a `bootstrap` command that initializes new servers. It could170- initialize a new virtual environment, setup apache appropriately etc.171-- Put configuration files into a separate version control repository172- and symlink the active configs into place.173-- You could also put your application code into a repository and check174- out the latest version on the server and then install. That way you175- can also easily go back to older versions.176-- hook in testing functionality so that you can deploy to an external177- server and run the test suite.178-179-Working with Fabric is fun and you will notice that it's quite magical to180-type ``fab deploy`` and see your application being deployed automatically181-to one or more remote servers.182-183-184-.. _Fabric: https://www.fabfile.org/modified:docs/patterns/index.rst-2 removed
17 unmodified lines18 packages19 appfactories20 appdispatch21 urlprocessors22- distribute23- fabric22 sqlite323 sqlalchemy24 fileuploads25 caching15 unmodified linesdeleted:docs/advanced_foreword.rst-46 removed
1-Foreword for Experienced Programmers2-====================================3-4-Thread-Locals in Flask5-----------------------6-7-One of the design decisions in Flask was that simple tasks should be simple;8-they should not take a lot of code and yet they should not limit you. Because9-of that, Flask has a few design choices that some people might find10-surprising or unorthodox. For example, Flask uses thread-local objects11-internally so that you don’t have to pass objects around from12-function to function within a request in order to stay threadsafe.13-This approach is convenient, but requires a valid14-request context for dependency injection or when attempting to reuse code which15-uses a value pegged to the request. The Flask project is honest about16-thread-locals, does not hide them, and calls out in the code and documentation17-where they are used.18-19-Develop for the Web with Caution20---------------------------------21-22-Always keep security in mind when building web applications.23-24-If you write a web application, you are probably allowing users to register25-and leave their data on your server. The users are entrusting you with data.26-And even if you are the only user that might leave data in your application,27-you still want that data to be stored securely.28-29-Unfortunately, there are many ways the security of a web application can be30-compromised. Flask protects you against one of the most common security31-problems of modern web applications: cross-site scripting (XSS). Unless you32-deliberately mark insecure HTML as secure, Flask and the underlying Jinja233-template engine have you covered. But there are many more ways to cause34-security problems.35-36-The documentation will warn you about aspects of web development that require37-attention to security. Some of these security concerns are far more complex38-than one might think, and we all sometimes underestimate the likelihood that a39-vulnerability will be exploited - until a clever attacker figures out a way to40-exploit our applications. And don't think that your application is not41-important enough to attract an attacker. Depending on the kind of attack,42-chances are that automated bots are probing for ways to fill your database with43-spam, links to malicious software, and the like.44-45-Flask is no different from any other framework in that you the developer must46-build with caution, watching for exploits when building to your requirements.modified:docs/config.rst+6 added-10 removed
392 unmodified lines393 394 Configuring from Python Files395 -----------------------------396 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 package400-handling tools (:doc:`/patterns/distribute`) and finally modifying the401-configuration file afterwards.397+Configuration becomes more useful if you can store it in a separate file, ideally398+located outside the actual application package. You can deploy your application, then399+separately configure it for the specific deployment.400 403-So a common pattern is this::401+A common pattern is this::402 403 app = Flask(__name__)404 app.config.from_object('yourapplication.default_settings')405 app.config.from_envvar('YOURAPPLICATION_SETTINGS')283 unmodified lines689 easily switch between different configs without having to touch the690 code at all. If you are working often on different projects you can691 even create your own script for sourcing that activates a virtualenv692 and exports the development configuration for you.695-- Use a tool like `fabric`_ in production to push code and696- configurations separately to the production server(s). For some697- details about how to do that, head over to the698- :doc:`/patterns/fabric` pattern.693+- Use a tool like `fabric`_ to push code and configuration separately694+ to the production server(s).695 696 .. _fabric: https://www.fabfile.org/697 698 82 unmodified linesmodified:docs/design.rst+24 added-1 removed
128 unmodified lines129 being present. You can easily use your own templating language, but an130 extension could still depend on Jinja itself.131 132 133-Micro with Dependencies133+What does "micro" mean?134 -----------------------135 136+“Micro” does not mean that your whole web application has to fit into a single137+Python file (although it certainly can), nor does it mean that Flask is lacking138+in functionality. The "micro" in microframework means Flask aims to keep the139+core simple but extensible. Flask won't make many decisions for you, such as140+what database to use. Those decisions that it does make, such as what141+templating engine to use, are easy to change. Everything else is up to you, so142+that Flask can be everything you need and nothing you don't.143+144+By default, Flask does not include a database abstraction layer, form145+validation or anything else where different libraries already exist that can146+handle that. Instead, Flask supports extensions to add such functionality to147+your application as if it was implemented in Flask itself. Numerous extensions148+provide database integration, form validation, upload handling, various open149+authentication technologies, and more. Flask may be "micro", but it's ready for150+production use on a variety of needs.151+152 Why does Flask call itself a microframework and yet it depends on two153 libraries (namely Werkzeug and Jinja2). Why shouldn't it? If we look154 over to the Ruby side of web development there we have a protocol very155 similar to WSGI. Just that it's called Rack there, but besides that it60 unmodified lines216 requirements and Flask could not meet those if it would force any of this217 into the core. The majority of web applications will need a template218 engine in some sort. However not every application needs a SQL database.219 220+As your codebase grows, you are free to make the design decisions appropriate221+for your project. Flask will continue to provide a very simple glue layer to222+the best that Python has to offer. You can implement advanced patterns in223+SQLAlchemy or another database tool, introduce non-relational data persistence224+as appropriate, and take advantage of framework-agnostic tools built for WSGI,225+the Python web interface.226+227 The idea of Flask is to build a good foundation for all applications.228 Everything else is up to you or extensions.deleted:docs/foreword.rst-53 removed
1-Foreword2-========3-4-Read this before you get started with Flask. This hopefully answers some5-questions about the purpose and goals of the project, and when you6-should or should not be using it.7-8-What does "micro" mean?9------------------------10-11-“Micro” does not mean that your whole web application has to fit into a single12-Python file (although it certainly can), nor does it mean that Flask is lacking13-in functionality. The "micro" in microframework means Flask aims to keep the14-core simple but extensible. Flask won't make many decisions for you, such as15-what database to use. Those decisions that it does make, such as what16-templating engine to use, are easy to change. Everything else is up to you, so17-that Flask can be everything you need and nothing you don't.18-19-By default, Flask does not include a database abstraction layer, form20-validation or anything else where different libraries already exist that can21-handle that. Instead, Flask supports extensions to add such functionality to22-your application as if it was implemented in Flask itself. Numerous extensions23-provide database integration, form validation, upload handling, various open24-authentication technologies, and more. Flask may be "micro", but it's ready for25-production use on a variety of needs.26-27-Configuration and Conventions28------------------------------29-30-Flask has many configuration values, with sensible defaults, and a few31-conventions when getting started. By convention, templates and static32-files are stored in subdirectories within the application's Python33-source tree, with the names :file:`templates` and :file:`static`34-respectively. While this can be changed, you usually don't have to,35-especially when getting started.36-37-Growing with Flask38-------------------39-40-Once you have Flask up and running, you'll find a variety of extensions41-available in the community to integrate your project for production.42-43-As your codebase grows, you are free to make the design decisions appropriate44-for your project. Flask will continue to provide a very simple glue layer to45-the best that Python has to offer. You can implement advanced patterns in46-SQLAlchemy or another database tool, introduce non-relational data persistence47-as appropriate, and take advantage of framework-agnostic tools built for WSGI,48-the Python web interface.49-50-Flask includes many hooks to customize its behavior. Should you need51-more customization, the Flask class is built for subclassing. If you are52-curious about the Flask design principles, head over to the section53-about :doc:`design`.deleted:docs/htmlfaq.rst-206 removed
1-HTML/XHTML FAQ2-==============3-4-The Flask documentation and example applications are using HTML5. You5-may notice that in many situations, when end tags are optional they are6-not used, so that the HTML is cleaner and faster to load. Because there7-is much confusion about HTML and XHTML among developers, this document tries8-to answer some of the major questions.9-10-11-History of XHTML12-----------------13-14-For a while, it appeared that HTML was about to be replaced by XHTML.15-However, barely any websites on the Internet are actual XHTML (which is16-HTML processed using XML rules). There are a couple of major reasons17-why this is the case. One of them is Internet Explorer's lack of proper18-XHTML support. The XHTML spec states that XHTML must be served with the MIME19-type :mimetype:`application/xhtml+xml`, but Internet Explorer refuses20-to read files with that MIME type.21-While it is relatively easy to configure Web servers to serve XHTML properly,22-few people do. This is likely because properly using XHTML can be quite23-painful.24-25-One of the most important causes of pain is XML's draconian (strict and26-ruthless) error handling. When an XML parsing error is encountered,27-the browser is supposed to show the user an ugly error message, instead28-of attempting to recover from the error and display what it can. Most of29-the (X)HTML generation on the web is based on non-XML template engines30-(such as Jinja, the one used in Flask) which do not protect you from31-accidentally creating invalid XHTML. There are XML based template engines,32-such as Kid and the popular Genshi, but they often come with a larger33-runtime overhead and are not as straightforward to use because they have34-to obey XML rules.35-36-The majority of users, however, assumed they were properly using XHTML.37-They wrote an XHTML doctype at the top of the document and self-closed all38-the necessary tags (``<br>`` becomes ``<br/>`` or ``<br></br>`` in XHTML).39-However, even if the document properly validates as XHTML, what really40-determines XHTML/HTML processing in browsers is the MIME type, which as41-said before is often not set properly. So the valid XHTML was being treated42-as invalid HTML.43-44-XHTML also changed the way JavaScript is used. To properly work with XHTML,45-programmers have to use the namespaced DOM interface with the XHTML46-namespace to query for HTML elements.47-48-History of HTML549-----------------50-51-Development of the HTML5 specification was started in 2004 under the name52-"Web Applications 1.0" by the Web Hypertext Application Technology Working53-Group, or WHATWG (which was formed by the major browser vendors Apple,54-Mozilla, and Opera) with the goal of writing a new and improved HTML55-specification, based on existing browser behavior instead of unrealistic56-and backwards-incompatible specifications.57-58-For example, in HTML4 ``<title/Hello/`` theoretically parses exactly the59-same as ``<title>Hello</title>``. However, since people were using60-XHTML-like tags along the lines of ``<link />``, browser vendors implemented61-the XHTML syntax over the syntax defined by the specification.62-63-In 2007, the specification was adopted as the basis of a new HTML64-specification under the umbrella of the W3C, known as HTML5. Currently,65-it appears that XHTML is losing traction, as the XHTML 2 working group has66-been disbanded and HTML5 is being implemented by all major browser vendors.67-68-HTML versus XHTML69------------------70-71-The following table gives you a quick overview of features available in72-HTML 4.01, XHTML 1.1 and HTML5. (XHTML 1.0 is not included, as it was73-superseded by XHTML 1.1 and the barely-used XHTML5.)74-75-.. tabularcolumns:: |p{9cm}|p{2cm}|p{2cm}|p{2cm}|76-77-+-----------------------------------------+----------+----------+----------+78-| | HTML4.01 | XHTML1.1 | HTML5 |79-+=========================================+==========+==========+==========+80-| ``<tag/value/`` == ``<tag>value</tag>`` | |Y| [1]_ | |N| | |N| |81-+-----------------------------------------+----------+----------+----------+82-| ``<br/>`` supported | |N| | |Y| | |Y| [2]_ |83-+-----------------------------------------+----------+----------+----------+84-| ``<script/>`` supported | |N| | |Y| | |N| |85-+-----------------------------------------+----------+----------+----------+86-| should be served as `text/html` | |Y| | |N| [3]_ | |Y| |87-+-----------------------------------------+----------+----------+----------+88-| should be served as | |N| | |Y| | |N| |89-| `application/xhtml+xml` | | | |90-+-----------------------------------------+----------+----------+----------+91-| strict error handling | |N| | |Y| | |N| |92-+-----------------------------------------+----------+----------+----------+93-| inline SVG | |N| | |Y| | |Y| |94-+-----------------------------------------+----------+----------+----------+95-| inline MathML | |N| | |Y| | |Y| |96-+-----------------------------------------+----------+----------+----------+97-| ``<video>`` tag | |N| | |N| | |Y| |98-+-----------------------------------------+----------+----------+----------+99-| ``<audio>`` tag | |N| | |N| | |Y| |100-+-----------------------------------------+----------+----------+----------+101-| New semantic tags like ``<article>`` | |N| | |N| | |Y| |102-+-----------------------------------------+----------+----------+----------+103-104-.. [1] This is an obscure feature inherited from SGML. It is usually not105- supported by browsers, for reasons detailed above.106-.. [2] This is for compatibility with server code that generates XHTML for107- tags such as ``<br>``. It should not be used in new code.108-.. [3] XHTML 1.0 is the last XHTML standard that allows to be served109- as `text/html` for backwards compatibility reasons.110-111-.. |Y| image:: _static/yes.png112- :alt: Yes113-.. |N| image:: _static/no.png114- :alt: No115-116-What does "strict" mean?117-------------------------118-119-HTML5 has strictly defined parsing rules, but it also specifies exactly120-how a browser should react to parsing errors - unlike XHTML, which simply121-states parsing should abort. Some people are confused by apparently122-invalid syntax that still generates the expected results (for example,123-missing end tags or unquoted attribute values).124-125-Some of these work because of the lenient error handling most browsers use126-when they encounter a markup error, others are actually specified. The127-following constructs are optional in HTML5 by standard, but have to be128-supported by browsers:129-130-- Wrapping the document in an ``<html>`` tag131-- Wrapping header elements in ``<head>`` or the body elements in132- ``<body>``133-- Closing the ``<p>``, ``<li>``, ``<dt>``, ``<dd>``, ``<tr>``,134- ``<td>``, ``<th>``, ``<tbody>``, ``<thead>``, or ``<tfoot>`` tags.135-- Quoting attributes, so long as they contain no whitespace or136- special characters (like ``<``, ``>``, ``'``, or ``"``).137-- Requiring boolean attributes to have a value.138-139-This means the following page in HTML5 is perfectly valid:140-141-.. sourcecode:: html142-143- <!doctype html>144- <title>Hello HTML5</title>145- <div class=header>146- <h1>Hello HTML5</h1>147- <p class=tagline>HTML5 is awesome148- </div>149- <ul class=nav>150- <li><a href=/index>Index</a>151- <li><a href=/downloads>Downloads</a>152- <li><a href=/about>About</a>153- </ul>154- <div class=body>155- <h2>HTML5 is probably the future</h2>156- <p>157- There might be some other things around but in terms of158- browser vendor support, HTML5 is hard to beat.159- <dl>160- <dt>Key 1161- <dd>Value 1162- <dt>Key 2163- <dd>Value 2164- </dl>165- </div>166-167-168-New technologies in HTML5169--------------------------170-171-HTML5 adds many new features that make Web applications easier to write172-and to use.173-174-- The ``<audio>`` and ``<video>`` tags provide a way to embed audio and175- video without complicated add-ons like QuickTime or Flash.176-- Semantic elements like ``<article>``, ``<header>``, ``<nav>``, and177- ``<time>`` that make content easier to understand.178-- The ``<canvas>`` tag, which supports a powerful drawing API, reducing179- the need for server-generated images to present data graphically.180-- New form control types like ``<input type="date">`` that allow user181- agents to make entering and validating values easier.182-- Advanced JavaScript APIs like Web Storage, Web Workers, Web Sockets,183- geolocation, and offline applications.184-185-Many other features have been added, as well. A good guide to new features186-in HTML5 is Mark Pilgrim's book, `Dive Into HTML5`_.187-Not all of them are supported in browsers yet, however, so use caution.188-189-.. _Dive Into HTML5: https://diveintohtml5.info/190-191-What should be used?192---------------------193-194-Currently, the answer is HTML5. There are very few reasons to use XHTML195-considering the latest developments in Web browsers. To summarize the196-reasons given above:197-198-- Internet Explorer has poor support for XHTML.199-- Many JavaScript libraries also do not support XHTML, due to the more200- complicated namespacing API it requires.201-- HTML5 adds several new features, including semantic tags and the202- long-awaited ``<audio>`` and ``<video>`` tags.203-- It has the support of most browser vendors behind it.204-- It is much easier to write, and more compact.205-206-For most applications, it is undoubtedly better to use HTML5 than XHTML.modified:docs/index.rst+5 added-9 removed
27 unmodified lines28 29 User's Guide30 ------------31 32-This part of the documentation, which is mostly prose, begins with some33-background information about Flask, then focuses on step-by-step34-instructions for web development with Flask.32+Flask provides configuration and conventions, with sensible defaults, to get started.33+This section of the documentation explains the different parts of the Flask framework34+and how they can be used, customized, and extended. Beyond Flask itself, look for35+community-maintained extensions to add even more functionality.36 37 .. toctree::38 :maxdepth: 239 39- foreword40- advanced_foreword40 installation41 quickstart42 tutorial/index43 templating11 unmodified lines55 cli56 server57 shell58 patterns/index59+ security60 deploying/index61 async-await62 63 11 unmodified lines75 76 Additional Notes77 ----------------78 79-Design notes, legal information and changelog are here for the interested.80-79 .. toctree::80 :maxdepth: 281 82 design85- htmlfaq86- security83 extensiondev84 contributing85 license86 changesmodified:docs/quickstart.rst+8 added
355 unmodified lines356 cumbersome because you have to do the HTML escaping on your own to keep357 the application secure. Because of that Flask configures the `Jinja2358 <https://palletsprojects.com/p/jinja/>`_ template engine for you automatically.359 360+Templates can be used to generate any type of text file. For web applications, you'll361+primarily be generating HTML pages, but you can also generate markdown, plain text for362+emails, any anything else.363+364+For a reference to HTML, CSS, and other web APIs, use the `MDN Web Docs`_.365+366+.. _MDN Web Docs: https://developer.mozilla.org/367+368 To render a template you can use the :func:`~flask.render_template`369 method. All you have to do is provide the name of the template and the370 variables you want to pass to the template engine as keyword arguments.371 Here's a simple example of how to render a template::536 unmodified linesmodified:src/flask/cli.py+1 added-1 removed
952 unmodified lines953 import code954 955 banner = (956 f"Python {sys.version} on {sys.platform}\n"957- f"App: {current_app.import_name} [{current_app.env}]\n"957+ f"App: {current_app.import_name}\n"958 f"Instance: {current_app.instance_path}"959 )960 ctx: dict = {}961 97 unmodified lines