Skip to content
Myr

Split foreword into two files; edited lots.

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

authored by Max · committed by Max · parent c78070d · Browse files · 2 files+104 added−81 removed
This commit

State

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

Diff stats

2 files+104 added−81 removed

  • other:+104 added−81 removed

2 files+104 added−81 removed

added:docs/advanced_foreword.rst+67 added
1Foreword for Experienced Programmers2====================================34This chapter is for programmers who have worked with other frameworks in the5past, and who may have more specific or esoteric concerns that the typical6user.78Threads in Flask9----------------1011One of the design decisions with Flask was that simple tasks should be simple;12they should not take a lot of code and yet they should not limit you. Because13of that we made a few design choices that some people might find surprising or14unorthodox. For example, Flask uses thread-local objects internally so that15you don’t have to pass objects around from function to function within a16request in order to stay threadsafe. While this is a really easy approach and17saves you a lot of time, it might also cause some troubles for very large18applications because changes on these thread-local objects can happen anywhere19in the same thread. In order to solve these problems we don’t hide the thread20locals for you but instead embrace them and provide you with a lot of tools to21make it as pleasant as possible to work with them.2223Web Development is Dangerous24----------------------------2526If you write a web application, you are probably allowing users to register27and leave their data on your server. The users are entrusting you with data.28And even if you are the only user that might leave data in your application,29you still want that data to be stored securely.3031Unfortunately, there are many ways the security of a web application can be32compromised. Flask protects you against one of the most common security33problems of modern web applications: cross-site scripting (XSS). Unless34you deliberately mark insecure HTML as secure, Flask and the underlying35Jinja2 template engine have you covered. But there are many more ways to36cause security problems.3738The documentation will warn you about aspects of web development that39require attention to security. Some of these security concerns40are far more complex than one might think, and we all sometimes underestimate41the likelihood that a vulnerability will be exploited - until a clever42attacker figures out a way to exploit our applications. And don't think43that your application is not important enough to attract an attacker.44Depending on the kind of attack, chances are that automated bots are45probing for ways to fill your database with spam, links to malicious46software, and the like.4748So always keep security in mind when doing web development.4950The Status of Python 351----------------------5253Currently the Python community is in the process of improving libraries to54support the new iteration of the Python programming language. While the55situation is greatly improving there are still some issues that make it56hard for us to switch over to Python 3 just now. These problems are57partially caused by changes in the language that went unreviewed for too58long, partially also because we have not quite worked out how the lower-59level API should change to account for the Unicode differences in Python 3.6061Werkzeug and Flask will be ported to Python 3 as soon as a solution for62the changes is found, and we will provide helpful tips how to upgrade63existing applications to Python 3. Until then, we strongly recommend64using Python 2.6 and 2.7 with activated Python 3 warnings during65development. If you plan on upgrading to Python 3 in the near future we66strongly recommend that you read `How to write forwards compatible67Python code <http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/>`_.
modified:docs/foreword.rst+37 added-81 removed
6 unmodified lines
78What does "micro" mean?9-----------------------1011Flask considers the "micro" in microframework to refer not only to the12simplicity and small size of the framework, but also to the fact that it does13not make many decisions for you. While Flask does pick a templating engine14for you, we won't make such decisions for your datastore or other parts.11“Micro” does not mean that your whole web application has to fit into12a single Python file (although it certainly can). Nor does it mean13that Flask is lacking in functionality. The "micro" in microframework14means Flask aims to keep the core simple but extensible. Flask won't make 15many decisions for you, such as what database to use. Those decisions that 16it does make, such as what templating engine to use, are easy to change. 17Everything else is up to you, so that Flask can be everything you need 18and nothing you don't.1916However, to us the term “micro” does not mean that the whole implementation17has to fit into a single Python file.20By default, Flask does not include a database abstraction layer, form21validation or anything else where different libraries already exist that can22handle that. Instead, FLask extensions add such functionality to your23application as if it was implemented in Flask itself. Numerous extensions24provide database integration, form validation, upload handling, various open25authentication technologies, and more. Flask may be "micro", but the26possibilities are endless.2719One of the design decisions with Flask was that simple tasks should be20simple; they should not take a lot of code and yet they should not limit you.21Because of that we made a few design choices that some people might find22surprising or unorthodox. For example, Flask uses thread-local objects23internally so that you don't have to pass objects around from function to24function within a request in order to stay threadsafe. While this is a25really easy approach and saves you a lot of time, it might also cause some26troubles for very large applications because changes on these thread-local27objects can happen anywhere in the same thread. In order to solve these28problems we don't hide the thread locals for you but instead embrace them29and provide you with a lot of tools to make it as pleasant as possible to30work with them.28Convention over Configuration29-----------------------------3032Flask is also based on convention over configuration, which means that33many things are preconfigured. For example, by convention templates and34static files are stored in subdirectories within the application's Python source tree.35While this can be changed you usually don't have to.31Flask is based on convention over configuration, which means that many things32are preconfigured. For example, by convention templates and static files are33stored in subdirectories within the application's Python source tree. While34this can be changed you usually don't have to. We want to minimize the time35you need to spend in order to get up and running, without assuming things 36about your needs.3737The main reason Flask is called a "microframework" is the idea38to keep the core simple but extensible. There is no database abstraction39layer, no form validation or anything else where different libraries40already exist that can handle that. However Flask supports41extensions to add such functionality to your application as if it42was implemented in Flask itself. There are currently extensions for43object-relational mappers, form validation, upload handling, various open44authentication technologies and more.38Growing Up39----------4046Since Flask is based on a very solid foundation there is not a lot of code47in Flask itself. As such it's easy to adapt even for large applications48and we are making sure that you can either configure it as much as49possible by subclassing things or by forking the entire codebase. If you50are interested in that, check out the :ref:`becomingbig` chapter.41Since Flask is based on a very solid foundation there is not a lot of code in42Flask itself. As such it's easy to adapt even for large applications and we43are making sure that you can either configure it as much as possible by44subclassing things or by forking the entire codebase. If you are interested45in that, check out the :ref:`becomingbig` chapter.4652If you are curious about the Flask design principles, head over to the53section about :ref:`design`.47If you are curious about the Flask design principles, head over to the section48about :ref:`design`.4955Web Development is Dangerous56----------------------------50For the Stalwart and Wizened...51-------------------------------5258If you write a web application, you are probably allowing users to register59and leave their data on your server. The users are entrusting you with data.60And even if you are the only user that might leave data in your application,61you still want that data to be stored securely.6263Unfortunately, there are many ways the security of a web application can be64compromised. Flask protects you against one of the most common security65problems of modern web applications: cross-site scripting (XSS). Unless66you deliberately mark insecure HTML as secure, Flask and the underlying67Jinja2 template engine have you covered. But there are many more ways to68cause security problems.6970The documentation will warn you about aspects of web development that71require attention to security. Some of these security concerns72are far more complex than one might think, and we all sometimes underestimate73the likelihood that a vulnerability will be exploited - until a clever74attacker figures out a way to exploit our applications. And don't think75that your application is not important enough to attract an attacker.76Depending on the kind of attack, chances are that automated bots are77probing for ways to fill your database with spam, links to malicious78software, and the like.7980So always keep security in mind when doing web development.8182The Status of Python 383----------------------8485Currently the Python community is in the process of improving libraries to86support the new iteration of the Python programming language. While the87situation is greatly improving there are still some issues that make it88hard for us to switch over to Python 3 just now. These problems are89partially caused by changes in the language that went unreviewed for too90long, partially also because we have not quite worked out how the lower-91level API should change to account for the Unicode differences in Python 3.9293Werkzeug and Flask will be ported to Python 3 as soon as a solution for94the changes is found, and we will provide helpful tips how to upgrade95existing applications to Python 3. Until then, we strongly recommend96using Python 2.6 and 2.7 with activated Python 3 warnings during97development. If you plan on upgrading to Python 3 in the near future we98strongly recommend that you read `How to write forwards compatible99Python code <http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/>`_.53If you're more curious about the minutiae of Flask's implementation, and54whether its structure is right for your needs, read the55:ref:`advanced_foreword`.