Skip to content
Myr

refactor or remove old docs (#4748)

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

authored by David Lord · committed by GitHub · parent 45b2c99 · Browse files · 10 files+43 added−681 removed
This commit

State

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

Diff stats

10 files+43 added−681 removed

  • other:+43 added−681 removed

10 files+43 added−681 removed

deleted:docs/patterns/distribute.rst-170 removed
1Deploying with Setuptools2=========================34`Setuptools`_, is an extension library that is commonly used to5distribute Python libraries and extensions. It extends distutils, a basic6module installation system shipped with Python to also support various more7complex constructs that make larger applications easier to distribute:89- **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.1920Flask itself, and all the libraries you can find on PyPI are distributed with21either setuptools or distutils.2223In this case we assume your application is called24: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 automate30the 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.3738Standard 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.4445A basic :file:`setup.py` file for a Flask application looks like this::4647 from setuptools import setup4849 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 )5859Please keep in mind that you have to list subpackages explicitly. If you60want setuptools to lookup the packages for you automatically, you can use61the ``find_packages`` function::6263 from setuptools import setup, find_packages6465 setup(66 ...67 packages=find_packages()68 )6970Most 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` file73and install all the entries that match as package data. We will use this74to distribute the static files and templates along with the Python module75(see :ref:`distributing-resources`). The ``zip_safe`` flag can be used to76force or prevent zip Archive creation. In general you probably don't want77your packages to be installed as zip files because some tools do not78support them and they make debugging a lot harder.798081Tagging Builds82--------------8384It is useful to distinguish between release and development builds. Add a85:file:`setup.cfg` file to configure these options. ::8687 [egg_info]88 tag_build = .dev89 tag_date = 19091 [aliases]92 release = egg_info -Db ''9394Running ``python setup.py sdist`` will create a development package95with ".dev" and the current date appended: ``flaskr-1.0.dev20160314.tar.gz``.96Running ``python setup.py release sdist`` will create a release package97with only the version: ``flaskr-1.0.tar.gz``.9899100.. _distributing-resources:101102Distributing Resources103----------------------104105If you try to install the package you just created, you will notice that106folders like :file:`static` or :file:`templates` are not installed for you. The107reason for this is that setuptools does not know which files to add for108you. 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 to110your tarball::111112 recursive-include yourapplication/templates *113 recursive-include yourapplication/static *114115Don't forget that even if you enlist them in your :file:`MANIFEST.in` file, they116won't be installed for you unless you set the `include_package_data`117parameter of the ``setup`` function to ``True``!118119120Declaring Dependencies121----------------------122123Dependencies are declared in the ``install_requires`` parameter as a list.124Each item in that list is the name of a package that should be pulled from125PyPI on installation. By default it will always use the most recent126version, but you can also provide minimum and maximum version127requirements. Here some examples::128129 install_requires=[130 'Flask>=0.2',131 'SQLAlchemy>=0.6',132 'BrokenPackage>=0.7,<=1.0'133 ]134135As mentioned earlier, dependencies are pulled from PyPI. What if you136want to depend on a package that cannot be found on PyPI and won't be137because it is an internal package you don't want to share with anyone?138Just do it as if there was a PyPI entry and provide a list of139alternative locations where setuptools should look for tarballs::140141 dependency_links=['http://example.com/yourfiles']142143Make sure that page has a directory listing and the links on the page are144pointing to the actual tarballs with their correct filenames as this is145how setuptools will find the files. If you have an internal company146server that contains the packages, provide the URL to that server.147148149Installing / Developing150-----------------------151152To install your application (ideally into a virtualenv) just run the153:file:`setup.py` script with the ``install`` parameter. It will install your154application into the virtualenv's site-packages folder and also download155and install all dependencies::156157 $ python setup.py install158159If you are developing on the package and also want the requirements to be160installed, you can use the ``develop`` command instead::161162 $ python setup.py develop163164This has the advantage of just installing a link to the site-packages165folder instead of copying the data over. You can then continue to work on166the code without having to run ``install`` again after each change.167168169.. _pip: https://pypi.org/project/pip/170.. _Setuptools: https://pypi.org/project/setuptools/
deleted:docs/patterns/fabric.rst-184 removed
1Deploying 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 properly6set 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 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.2223Creating the first Fabfile24--------------------------2526A fabfile is what controls what Fabric executes. It is named :file:`fabfile.py`27and executed by the `fab` command. All the functions defined in that file28will show up as `fab` subcommands. They are executed on one or more29hosts. These hosts can be defined either in the fabfile or on the command30line. In this case we will add them to the fabfile.3132This is a basic first example that has the ability to upload the current33source code to the server and install it into a pre-existing34virtual environment::3536 from fabric.api import *3738 # 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']4243 def pack():44 # build the package45 local('python setup.py sdist --formats=gztar', capture=False)4647 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'5152 # upload the package to the temporary folder on the server53 put(f'dist/{filename}', f'/tmp/{filename}')5455 # install the package in the application's virtualenv with pip56 run(f'/var/www/yourapplication/env/bin/pip install /tmp/{filename}')5758 # remove the uploaded package59 run(f'rm -r /tmp/{filename}')6061 # touch the .wsgi file to trigger a reload in mod_wsgi62 run('touch /var/www/yourapplication.wsgi')6364Running Fabfiles65----------------6667Now how do you execute that fabfile? You use the `fab` command. To68deploy the current version of the code on the remote server you would use69this command::7071 $ fab pack deploy7273However 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. Furthermore76are we not creating the configuration or ``.wsgi`` file on the server. So77how do we bootstrap a new server into our infrastructure?7879This now depends on the number of servers we want to set up. If we just80have one application server (which the majority of applications will81have), creating a command in the fabfile for this is overkill. But82obviously you can do that. In that case you would probably call it83`setup` or `bootstrap` and then pass the servername explicitly on the84command line::8586 $ fab -H newserver.example.com bootstrap8788To setup a new server you would roughly do these steps:89901. Create the directory structure in :file:`/var/www`::9192 $ mkdir /var/www/yourapplication93 $ cd /var/www/yourapplication94 $ virtualenv --distribute env95962. Upload a new :file:`application.wsgi` file to the server and the97 configuration file for the application (eg: :file:`application.cfg`)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.102 See :doc:`/deploying/mod_wsgi`.103104So now the question is, where do the :file:`application.wsgi` and105:file:`application.cfg` files come from?106107The WSGI File108-------------109110The WSGI file has to import the application and also to set an environment111variable so that the application knows where to look for the config. This112is a short example that does exactly that::113114 import os115 os.environ['YOURAPPLICATION_CONFIG'] = '/var/www/yourapplication/application.cfg'116 from yourapplication import app117118The application itself then has to initialize itself like this to look for119the config at that environment variable::120121 app = Flask(__name__)122 app.config.from_object('yourapplication.default_config')123 app.config.from_envvar('YOURAPPLICATION_CONFIG')124125This approach is explained in detail in the :doc:`/config` section of the126documentation.127128The Configuration File129----------------------130131Now as mentioned above, the application will find the correct132configuration file by looking up the ``YOURAPPLICATION_CONFIG`` environment133variable. So we have to put the configuration in a place where the134application will able to find it. Configuration files have the unfriendly135quality of being different on all computers, so you do not version them136usually.137138A popular approach is to store configuration files for different servers139in a separate version control repository and check them out on all140servers. Then symlink the file that is active for the server into the141location where it's expected (eg: :file:`/var/www/yourapplication`).142143Either way, in our case here we only expect one or two servers and we can144upload them ahead of time by hand.145146147First Deployment148----------------149150Now we can do our first deployment. We have set up the servers so that151they have their virtual environments and activated apache configs. Now we152can pack up the application and deploy it::153154 $ fab pack deploy155156Fabric will now connect to all servers and run the commands as written157down in the fabfile. First it will execute pack so that we have our158tarball ready and then it will execute deploy and upload the source code159to all servers and install it there. Thanks to the :file:`setup.py` file we160will automatically pull in the required libraries into our virtual161environment.162163Next Steps164----------165166From that point onwards there is so much that can be done to make167deployment actually fun:168169- 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.178179Working with Fabric is fun and you will notice that it's quite magical to180type ``fab deploy`` and see your application being deployed automatically181to one or more remote servers.182183184.. _Fabric: https://www.fabfile.org/
modified:docs/patterns/index.rst-2 removed
17 unmodified lines
18 packages19 appfactories20 appdispatch21 urlprocessors22 distribute23 fabric22 sqlite323 sqlalchemy24 fileuploads25 caching
15 unmodified lines
deleted:docs/advanced_foreword.rst-46 removed
1Foreword for Experienced Programmers2====================================34Thread-Locals in Flask5----------------------67One of the design decisions in Flask was that simple tasks should be simple;8they should not take a lot of code and yet they should not limit you. Because9of that, Flask has a few design choices that some people might find10surprising or unorthodox. For example, Flask uses thread-local objects11internally so that you don’t have to pass objects around from12function to function within a request in order to stay threadsafe.13This approach is convenient, but requires a valid14request context for dependency injection or when attempting to reuse code which15uses a value pegged to the request. The Flask project is honest about16thread-locals, does not hide them, and calls out in the code and documentation17where they are used.1819Develop for the Web with Caution20--------------------------------2122Always keep security in mind when building web applications.2324If you write a web application, you are probably allowing users to register25and leave their data on your server. The users are entrusting you with data.26And even if you are the only user that might leave data in your application,27you still want that data to be stored securely.2829Unfortunately, there are many ways the security of a web application can be30compromised. Flask protects you against one of the most common security31problems of modern web applications: cross-site scripting (XSS). Unless you32deliberately mark insecure HTML as secure, Flask and the underlying Jinja233template engine have you covered. But there are many more ways to cause34security problems.3536The documentation will warn you about aspects of web development that require37attention to security. Some of these security concerns are far more complex38than one might think, and we all sometimes underestimate the likelihood that a39vulnerability will be exploited - until a clever attacker figures out a way to40exploit our applications. And don't think that your application is not41important enough to attract an attacker. Depending on the kind of attack,42chances are that automated bots are probing for ways to fill your database with43spam, links to malicious software, and the like.4445Flask is no different from any other framework in that you the developer must46build with caution, watching for exploits when building to your requirements.
modified:docs/config.rst+6 added-10 removed
392 unmodified lines
393394Configuring from Python Files395-----------------------------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 package400handling tools (:doc:`/patterns/distribute`) and finally modifying the401configuration file afterwards.397Configuration becomes more useful if you can store it in a separate file, ideally398located outside the actual application package. You can deploy your application, then399separately configure it for the specific deployment.400403So a common pattern is this::401A common pattern is this::402403 app = Flask(__name__)404 app.config.from_object('yourapplication.default_settings')405 app.config.from_envvar('YOURAPPLICATION_SETTINGS')
283 unmodified lines
689 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).695696.. _fabric: https://www.fabfile.org/697698
82 unmodified lines
modified:docs/design.rst+24 added-1 removed
128 unmodified lines
129being present. You can easily use your own templating language, but an130extension could still depend on Jinja itself.131132133Micro with Dependencies133What does "micro" mean?134-----------------------135136“Micro” does not mean that your whole web application has to fit into a single137Python file (although it certainly can), nor does it mean that Flask is lacking138in functionality. The "micro" in microframework means Flask aims to keep the139core simple but extensible. Flask won't make many decisions for you, such as140what database to use. Those decisions that it does make, such as what141templating engine to use, are easy to change. Everything else is up to you, so142that Flask can be everything you need and nothing you don't.143144By default, Flask does not include a database abstraction layer, form145validation or anything else where different libraries already exist that can146handle that. Instead, Flask supports extensions to add such functionality to147your application as if it was implemented in Flask itself. Numerous extensions148provide database integration, form validation, upload handling, various open149authentication technologies, and more. Flask may be "micro", but it's ready for150production use on a variety of needs.151152Why does Flask call itself a microframework and yet it depends on two153libraries (namely Werkzeug and Jinja2). Why shouldn't it? If we look154over to the Ruby side of web development there we have a protocol very155similar to WSGI. Just that it's called Rack there, but besides that it
60 unmodified lines
216requirements and Flask could not meet those if it would force any of this217into the core. The majority of web applications will need a template218engine in some sort. However not every application needs a SQL database.219220As your codebase grows, you are free to make the design decisions appropriate221for your project. Flask will continue to provide a very simple glue layer to222the best that Python has to offer. You can implement advanced patterns in223SQLAlchemy or another database tool, introduce non-relational data persistence224as appropriate, and take advantage of framework-agnostic tools built for WSGI,225the Python web interface.226227The idea of Flask is to build a good foundation for all applications.228Everything else is up to you or extensions.
deleted:docs/foreword.rst-53 removed
1Foreword2========34Read this before you get started with Flask. This hopefully answers some5questions about the purpose and goals of the project, and when you6should or should not be using it.78What does "micro" mean?9-----------------------1011“Micro” does not mean that your whole web application has to fit into a single12Python file (although it certainly can), nor does it mean that Flask is lacking13in functionality. The "micro" in microframework means Flask aims to keep the14core simple but extensible. Flask won't make many decisions for you, such as15what database to use. Those decisions that it does make, such as what16templating engine to use, are easy to change. Everything else is up to you, so17that Flask can be everything you need and nothing you don't.1819By default, Flask does not include a database abstraction layer, form20validation or anything else where different libraries already exist that can21handle that. Instead, Flask supports extensions to add such functionality to22your application as if it was implemented in Flask itself. Numerous extensions23provide database integration, form validation, upload handling, various open24authentication technologies, and more. Flask may be "micro", but it's ready for25production use on a variety of needs.2627Configuration and Conventions28-----------------------------2930Flask has many configuration values, with sensible defaults, and a few31conventions when getting started. By convention, templates and static32files are stored in subdirectories within the application's Python33source tree, with the names :file:`templates` and :file:`static`34respectively. While this can be changed, you usually don't have to,35especially when getting started.3637Growing with Flask38------------------3940Once you have Flask up and running, you'll find a variety of extensions41available in the community to integrate your project for production.4243As your codebase grows, you are free to make the design decisions appropriate44for your project. Flask will continue to provide a very simple glue layer to45the best that Python has to offer. You can implement advanced patterns in46SQLAlchemy or another database tool, introduce non-relational data persistence47as appropriate, and take advantage of framework-agnostic tools built for WSGI,48the Python web interface.4950Flask includes many hooks to customize its behavior. Should you need51more customization, the Flask class is built for subclassing. If you are52curious about the Flask design principles, head over to the section53about :doc:`design`.
deleted:docs/htmlfaq.rst-206 removed
1HTML/XHTML FAQ2==============34The Flask documentation and example applications are using HTML5. You5may notice that in many situations, when end tags are optional they are6not used, so that the HTML is cleaner and faster to load. Because there7is much confusion about HTML and XHTML among developers, this document tries8to answer some of the major questions.91011History of XHTML12----------------1314For a while, it appeared that HTML was about to be replaced by XHTML.15However, barely any websites on the Internet are actual XHTML (which is16HTML processed using XML rules). There are a couple of major reasons17why this is the case. One of them is Internet Explorer's lack of proper18XHTML support. The XHTML spec states that XHTML must be served with the MIME19type :mimetype:`application/xhtml+xml`, but Internet Explorer refuses20to read files with that MIME type.21While it is relatively easy to configure Web servers to serve XHTML properly,22few people do. This is likely because properly using XHTML can be quite23painful.2425One of the most important causes of pain is XML's draconian (strict and26ruthless) error handling. When an XML parsing error is encountered,27the browser is supposed to show the user an ugly error message, instead28of attempting to recover from the error and display what it can. Most of29the (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 from31accidentally creating invalid XHTML. There are XML based template engines,32such as Kid and the popular Genshi, but they often come with a larger33runtime overhead and are not as straightforward to use because they have34to obey XML rules.3536The majority of users, however, assumed they were properly using XHTML.37They wrote an XHTML doctype at the top of the document and self-closed all38the necessary tags (``<br>`` becomes ``<br/>`` or ``<br></br>`` in XHTML).39However, even if the document properly validates as XHTML, what really40determines XHTML/HTML processing in browsers is the MIME type, which as41said before is often not set properly. So the valid XHTML was being treated42as invalid HTML.4344XHTML also changed the way JavaScript is used. To properly work with XHTML,45programmers have to use the namespaced DOM interface with the XHTML46namespace to query for HTML elements.4748History of HTML549----------------5051Development of the HTML5 specification was started in 2004 under the name52"Web Applications 1.0" by the Web Hypertext Application Technology Working53Group, or WHATWG (which was formed by the major browser vendors Apple,54Mozilla, and Opera) with the goal of writing a new and improved HTML55specification, based on existing browser behavior instead of unrealistic56and backwards-incompatible specifications.5758For example, in HTML4 ``<title/Hello/`` theoretically parses exactly the59same as ``<title>Hello</title>``. However, since people were using60XHTML-like tags along the lines of ``<link />``, browser vendors implemented61the XHTML syntax over the syntax defined by the specification.6263In 2007, the specification was adopted as the basis of a new HTML64specification under the umbrella of the W3C, known as HTML5. Currently,65it appears that XHTML is losing traction, as the XHTML 2 working group has66been disbanded and HTML5 is being implemented by all major browser vendors.6768HTML versus XHTML69-----------------7071The following table gives you a quick overview of features available in72HTML 4.01, XHTML 1.1 and HTML5. (XHTML 1.0 is not included, as it was73superseded by XHTML 1.1 and the barely-used XHTML5.)7475.. tabularcolumns:: |p{9cm}|p{2cm}|p{2cm}|p{2cm}|7677+-----------------------------------------+----------+----------+----------+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+-----------------------------------------+----------+----------+----------+103104.. [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.110111.. |Y| image:: _static/yes.png112 :alt: Yes113.. |N| image:: _static/no.png114 :alt: No115116What does "strict" mean?117------------------------118119HTML5 has strictly defined parsing rules, but it also specifies exactly120how a browser should react to parsing errors - unlike XHTML, which simply121states parsing should abort. Some people are confused by apparently122invalid syntax that still generates the expected results (for example,123missing end tags or unquoted attribute values).124125Some of these work because of the lenient error handling most browsers use126when they encounter a markup error, others are actually specified. The127following constructs are optional in HTML5 by standard, but have to be128supported by browsers:129130- 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.138139This means the following page in HTML5 is perfectly valid:140141.. sourcecode:: html142143 <!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>166167168New technologies in HTML5169-------------------------170171HTML5 adds many new features that make Web applications easier to write172and to use.173174- 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.184185Many other features have been added, as well. A good guide to new features186in HTML5 is Mark Pilgrim's book, `Dive Into HTML5`_.187Not all of them are supported in browsers yet, however, so use caution.188189.. _Dive Into HTML5: https://diveintohtml5.info/190191What should be used?192--------------------193194Currently, the answer is HTML5. There are very few reasons to use XHTML195considering the latest developments in Web browsers. To summarize the196reasons given above:197198- 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.205206For most applications, it is undoubtedly better to use HTML5 than XHTML.
modified:docs/index.rst+5 added-9 removed
27 unmodified lines
2829User's Guide30------------3132This part of the documentation, which is mostly prose, begins with some33background information about Flask, then focuses on step-by-step34instructions for web development with Flask.32Flask provides configuration and conventions, with sensible defaults, to get started.33This section of the documentation explains the different parts of the Flask framework34and how they can be used, customized, and extended. Beyond Flask itself, look for35community-maintained extensions to add even more functionality.3637.. toctree::38 :maxdepth: 23939 foreword40 advanced_foreword40 installation41 quickstart42 tutorial/index43 templating
11 unmodified lines
55 cli56 server57 shell58 patterns/index59 security60 deploying/index61 async-await6263
11 unmodified lines
7576Additional Notes77----------------7879Design notes, legal information and changelog are here for the interested.8079.. toctree::80 :maxdepth: 28182 design85 htmlfaq86 security83 extensiondev84 contributing85 license86 changes
modified:docs/quickstart.rst+8 added
355 unmodified lines
356cumbersome because you have to do the HTML escaping on your own to keep357the application secure. Because of that Flask configures the `Jinja2358<https://palletsprojects.com/p/jinja/>`_ template engine for you automatically.359360Templates can be used to generate any type of text file. For web applications, you'll361primarily be generating HTML pages, but you can also generate markdown, plain text for362emails, any anything else.363364For a reference to HTML, CSS, and other web APIs, use the `MDN Web Docs`_.365366.. _MDN Web Docs: https://developer.mozilla.org/367368To render a template you can use the :func:`~flask.render_template`369method. All you have to do is provide the name of the template and the370variables you want to pass to the template engine as keyword arguments.371Here's a simple example of how to render a template::
536 unmodified lines