Merge pull request #438 from garbados/improve_foreword
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Improve foreword
authored by Ron DuPlain · committed by Ron DuPlain · parents 9601016, 8f568cf · Browse files · 2 files·+104 added−82 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−82 removed
- other:+104 added−82 removed
Provenance
- Commit
d626787- Tree
e1c520e- Author
Ron DuPlain <ron.duplain@gmail.com>- Committer
Ron DuPlain <ron.duplain@gmail.com>- Parent 1
9601016- Parent 2
8f568cf
2 files changed+104 added−82 removed
added:docs/advanced_foreword.rst+67 added
1+Foreword for Experienced Programmers2+====================================3+4+This chapter is for programmers who have worked with other frameworks in the5+past, and who may have more specific or esoteric concerns that the typical6+user.7+8+Threads in Flask9+----------------10+11+One of the design decisions with Flask was that simple tasks should be simple;12+they should not take a lot of code and yet they should not limit you. Because13+of that we made a few design choices that some people might find surprising or14+unorthodox. For example, Flask uses thread-local objects internally so that15+you don’t have to pass objects around from function to function within a16+request in order to stay threadsafe. While this is a really easy approach and17+saves you a lot of time, it might also cause some troubles for very large18+applications because changes on these thread-local objects can happen anywhere19+in the same thread. In order to solve these problems we don’t hide the thread20+locals for you but instead embrace them and provide you with a lot of tools to21+make it as pleasant as possible to work with them.22+23+Web Development is Dangerous24+----------------------------25+26+If you write a web application, you are probably allowing users to register27+and leave their data on your server. The users are entrusting you with data.28+And even if you are the only user that might leave data in your application,29+you still want that data to be stored securely.30+31+Unfortunately, there are many ways the security of a web application can be32+compromised. Flask protects you against one of the most common security33+problems of modern web applications: cross-site scripting (XSS). Unless34+you deliberately mark insecure HTML as secure, Flask and the underlying35+Jinja2 template engine have you covered. But there are many more ways to36+cause security problems.37+38+The documentation will warn you about aspects of web development that39+require attention to security. Some of these security concerns40+are far more complex than one might think, and we all sometimes underestimate41+the likelihood that a vulnerability will be exploited - until a clever42+attacker figures out a way to exploit our applications. And don't think43+that your application is not important enough to attract an attacker.44+Depending on the kind of attack, chances are that automated bots are45+probing for ways to fill your database with spam, links to malicious46+software, and the like.47+48+So always keep security in mind when doing web development.49+50+The Status of Python 351+----------------------52+53+Currently the Python community is in the process of improving libraries to54+support the new iteration of the Python programming language. While the55+situation is greatly improving there are still some issues that make it56+hard for us to switch over to Python 3 just now. These problems are57+partially caused by changes in the language that went unreviewed for too58+long, partially also because we have not quite worked out how the lower-59+level API should change to account for the Unicode differences in Python 3.60+61+Werkzeug and Flask will be ported to Python 3 as soon as a solution for62+the changes is found, and we will provide helpful tips how to upgrade63+existing applications to Python 3. Until then, we strongly recommend64+using Python 2.6 and 2.7 with activated Python 3 warnings during65+development. If you plan on upgrading to Python 3 in the near future we66+strongly recommend that you read `How to write forwards compatible67+Python code <http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/>`_.modified:docs/foreword.rst+37 added-82 removed
6 unmodified lines7 8 What does "micro" mean?9 -----------------------10 11-To me, the "micro" in microframework refers not only to the simplicity and12-small size of the framework, but also the fact that it does not make many13-decisions for you. While Flask does pick a templating engine for you, we14-won't make such decisions for your datastore or other parts.11+“Micro” does not mean that your whole web application has to fit into12+a single Python file (although it certainly can). Nor does it mean13+that Flask is lacking in functionality. The "micro" in microframework14+means Flask aims to keep the core simple but extensible. Flask won't make 15+many decisions for you, such as what database to use. Those decisions that 16+it does make, such as what templating engine to use, are easy to change. 17+Everything else is up to you, so that Flask can be everything you need 18+and nothing you don't.19 16-However, to us the term “micro” does not mean that the whole implementation17-has to fit into a single Python file.20+By default, Flask does not include a database abstraction layer, form21+validation or anything else where different libraries already exist that can22+handle that. Instead, FLask extensions add such functionality to your23+application as if it was implemented in Flask itself. Numerous extensions24+provide database integration, form validation, upload handling, various open25+authentication technologies, and more. Flask may be "micro", but the26+possibilities are endless.27 19-One of the design decisions with Flask was that simple tasks should be20-simple; they should not take a lot of code and yet they should not limit you.21-Because of that we made a few design choices that some people might find22-surprising or unorthodox. For example, Flask uses thread-local objects23-internally so that you don't have to pass objects around from function to24-function within a request in order to stay threadsafe. While this is a25-really easy approach and saves you a lot of time, it might also cause some26-troubles for very large applications because changes on these thread-local27-objects can happen anywhere in the same thread. In order to solve these28-problems we don't hide the thread locals for you but instead embrace them29-and provide you with a lot of tools to make it as pleasant as possible to30-work with them.28+Convention over Configuration29+-----------------------------30 32-Flask is also based on convention over configuration, which means that33-many things are preconfigured. For example, by convention templates and34-static files are stored in subdirectories within the application's Python source tree.35-While this can be changed you usually don't have to.31+Flask is based on convention over configuration, which means that many things32+are preconfigured. For example, by convention templates and static files are33+stored in subdirectories within the application's Python source tree. While34+this can be changed you usually don't have to. We want to minimize the time35+you need to spend in order to get up and running, without assuming things 36+about your needs.37 37-The main reason Flask is called a "microframework" is the idea38-to keep the core simple but extensible. There is no database abstraction39-layer, no form validation or anything else where different libraries40-already exist that can handle that. However Flask supports41-extensions to add such functionality to your application as if it42-was implemented in Flask itself. There are currently extensions for43-object-relational mappers, form validation, upload handling, various open44-authentication technologies and more.38+Growing Up39+----------40 46-Since Flask is based on a very solid foundation there is not a lot of code47-in Flask itself. As such it's easy to adapt even for large applications48-and we are making sure that you can either configure it as much as49-possible by subclassing things or by forking the entire codebase. If you50-are interested in that, check out the :ref:`becomingbig` chapter.41+Since Flask is based on a very solid foundation there is not a lot of code in42+Flask itself. As such it's easy to adapt even for large applications and we43+are making sure that you can either configure it as much as possible by44+subclassing things or by forking the entire codebase. If you are interested45+in that, check out the :ref:`becomingbig` chapter.46 52-If you are curious about the Flask design principles, head over to the53-section about :ref:`design`.47+If you are curious about the Flask design principles, head over to the section48+about :ref:`design`.49 55-Web Development is Dangerous56-----------------------------50+For the Stalwart and Wizened...51+-------------------------------52 58-I'm not joking. Well, maybe a little. If you write a web59-application, you are probably allowing users to register and leave their60-data on your server. The users are entrusting you with data. And even if61-you are the only user that might leave data in your application, you still62-want that data to be stored securely.63-64-Unfortunately, there are many ways the security of a web application can be65-compromised. Flask protects you against one of the most common security66-problems of modern web applications: cross-site scripting (XSS). Unless67-you deliberately mark insecure HTML as secure, Flask and the underlying68-Jinja2 template engine have you covered. But there are many more ways to69-cause security problems.70-71-The documentation will warn you about aspects of web development that72-require attention to security. Some of these security concerns73-are far more complex than one might think, and we all sometimes underestimate74-the likelihood that a vulnerability will be exploited - until a clever75-attacker figures out a way to exploit our applications. And don't think76-that your application is not important enough to attract an attacker.77-Depending on the kind of attack, chances are that automated bots are78-probing for ways to fill your database with spam, links to malicious79-software, and the like.80-81-So always keep security in mind when doing web development.82-83-The Status of Python 384-----------------------85-86-Currently the Python community is in the process of improving libraries to87-support the new iteration of the Python programming language. While the88-situation is greatly improving there are still some issues that make it89-hard for us to switch over to Python 3 just now. These problems are90-partially caused by changes in the language that went unreviewed for too91-long, partially also because we have not quite worked out how the lower-92-level API should change to account for the Unicode differences in Python 3.93-94-Werkzeug and Flask will be ported to Python 3 as soon as a solution for95-the changes is found, and we will provide helpful tips how to upgrade96-existing applications to Python 3. Until then, we strongly recommend97-using Python 2.6 and 2.7 with activated Python 3 warnings during98-development. If you plan on upgrading to Python 3 in the near future we99-strongly recommend that you read `How to write forwards compatible100-Python code <http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/>`_.53+If you're more curious about the minutiae of Flask's implementation, and54+whether its structure is right for your needs, read the55+:ref:`advanced_foreword`.