Skip to content
Myr

Fixed linebreaks.

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

authored by Max · committed by Max · parent 74a72e8 · Browse files · 1 file+77 added−73 removed
This commit

State

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

Diff stats

1 file+77 added−73 removed

  • other:+77 added−73 removed

1 file+77 added−73 removed

modified:docs/foreword.rst+77 added-73 removed
1Foreword1Foreword 2========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.4Read this before you get started with Flask. This hopefully answers5some questions about the purpose and goals of the project, and when6you should or should not be using it.78What does "micro" mean?8What does "micro" mean? 9-----------------------1011As Flask considers it, the "micro" in microframework refers not only to the simplicity and12small size of the framework, but also the fact that it does not make many13decisions for you. While Flask does pick a templating engine for you, we14won't make such decisions for your datastore or other parts.11As Flask considers it, the "micro" in microframework refers not only12to the simplicity and small size of the framework, but also the fact13that it does not make many decisions for you. While Flask does pick a14templating engine for you, we won't make such decisions for your15datastore or other parts.1616However, to us the term “micro” does not mean that the whole implementation17has to fit into a single Python file.17However, to us the term “micro” does not mean that the whole18implementation has to fit into a single Python file.1920One 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.21simple; they should not take a lot of code and yet they should not22limit you. Because of that we made a few design choices that some23people might find surprising or unorthodox. For example, Flask uses24thread-local objects internally so that you don't have to pass objects25around from function to function within a request in order to stay26threadsafe. While this is a really easy approach and saves you a lot27of time, it might also cause some troubles for very large applications28because changes on these thread-local objects can happen anywhere in29the same thread. In order to solve these problems we don't hide the30thread locals for you but instead embrace them and provide you with a31lot of tools to make it as pleasant as possible to work with them.3233Flask 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.34many things are preconfigured. For example, by convention templates35and static files are stored in subdirectories within the application's36Python source tree. While this can be changed you usually don't have37to.3837The main reason Flask is called a "microframework" is the idea38to keep the core simple but extensible. There is no database abstraction39The main reason Flask is called a "microframework" is the idea to keep40the core simple but extensible. There is no database abstraction41layer, 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.42already exist that can handle that. However Flask supports extensions43to add such functionality to your application as if it was implemented44in Flask itself. There are currently extensions for object-relational45mappers, form validation, upload handling, various open authentication46technologies and more.4746Since 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.48Since Flask is based on a very solid foundation there is not a lot of49code in Flask itself. As such it's easy to adapt even for large50applications and we are making sure that you can either configure it51as much as possible by subclassing things or by forking the entire52codebase. If you are interested in that, check out the53:ref:`becomingbig` chapter.5455If you are curious about the Flask design principles, head over to the56section about :ref:`design`.5755Web Development is Dangerous56----------------------------58Web Development is Dangerous ----------------------------5958If you write a web59application, you are probably allowing users to register and leave their60data on your server. The users are entrusting you with data. And even if61you are the only user that might leave data in your application, you still62want that data to be stored securely.60If you write a web application, you are probably allowing users to61register and leave their data on your server. The users are62entrusting you with data. And even if you are the only user that63might leave data in your application, you still want that data to be64stored securely.6564Unfortunately, there are many ways the security of a web application can be65compromised. Flask protects you against one of the most common security66problems of modern web applications: cross-site scripting (XSS). Unless67you deliberately mark insecure HTML as secure, Flask and the underlying68Jinja2 template engine have you covered. But there are many more ways to69cause security problems.66Unfortunately, there are many ways the security of a web application67can be compromised. Flask protects you against one of the most common68security problems of modern web applications: cross-site scripting69(XSS). Unless you deliberately mark insecure HTML as secure, Flask70and the underlying Jinja2 template engine have you covered. But there71are many more ways to cause security problems.7273The documentation will warn you about aspects of web development that72require attention to security. Some of these security concerns73are far more complex than one might think, and we all sometimes underestimate74the likelihood that a vulnerability will be exploited - until a clever75attacker figures out a way to exploit our applications. And don't think76that your application is not important enough to attract an attacker.77Depending on the kind of attack, chances are that automated bots are78probing for ways to fill your database with spam, links to malicious79software, and the like.74require attention to security. Some of these security concerns are75far more complex than one might think, and we all sometimes76underestimate the likelihood that a vulnerability will be exploited -77until a clever attacker figures out a way to exploit our applications.78And don't think that your application is not important enough to79attract an attacker. Depending on the kind of attack, chances are that80automated bots are probing for ways to fill your database with spam,81links to malicious software, and the like.8283So always keep security in mind when doing web development.8483The Status of Python 385The Status of Python 3 86----------------------8786Currently the Python community is in the process of improving libraries to87support the new iteration of the Python programming language. While the88situation is greatly improving there are still some issues that make it89hard for us to switch over to Python 3 just now. These problems are90partially caused by changes in the language that went unreviewed for too91long, partially also because we have not quite worked out how the lower-92level API should change to account for the Unicode differences in Python 3.88Currently the Python community is in the process of improving89libraries to support the new iteration of the Python programming90language. While the situation is greatly improving there are still91some issues that make it hard for us to switch over to Python 3 just92now. These problems are partially caused by changes in the language93that went unreviewed for too long, partially also because we have not94quite worked out how the lower- level API should change to account for95the Unicode differences in Python 3.9694Werkzeug and Flask will be ported to Python 3 as soon as a solution for95the changes is found, and we will provide helpful tips how to upgrade96existing applications to Python 3. Until then, we strongly recommend97using Python 2.6 and 2.7 with activated Python 3 warnings during98development. If you plan on upgrading to Python 3 in the near future we99strongly recommend that you read `How to write forwards compatible100Python code <http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/>`_.97Werkzeug and Flask will be ported to Python 3 as soon as a solution98for the changes is found, and we will provide helpful tips how to99upgrade existing applications to Python 3. Until then, we strongly100recommend using Python 2.6 and 2.7 with activated Python 3 warnings101during development. If you plan on upgrading to Python 3 in the near102future we strongly recommend that you read `How to write forwards103compatible Python code <http://lucumr.pocoo.org/2011/1/22/forwards-104compatible-python/>`_.