Fixed various stylistic issues in documentation
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by FND · committed by FND · parent a9726c4 · Browse files · 3 files·+79 added−80 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+79 added−80 removed
- other:+79 added−80 removed
Provenance
- Commit
7ccca13- Tree
f18ced0- Author
FND <fnd@fnd-oda.(none)>- Committer
FND <fnd@fnd-oda.(none)>- Parent
a9726c4
3 files changed+79 added−80 removed
modified:docs/foreword.rst+14 added-14 removed
7 unmodified lines8 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 much12+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.15 16-For us however the term “micro” does not mean that the whole implementation16+However, to us the term “micro” does not mean that the whole implementation17 has to fit into a single Python file.18 19 One of the design decisions with Flask was that simple tasks should be20-simple and not take up a lot of code and yet not limit yourself. Because21-of that we took a few design choices that some people might find20+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 some3 unmodified lines29 and provide you with a lot of tools to make it as pleasant as possible to30 work with them.31 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 in subdirectories within the Python source tree of the35-application. While this can be changed you usually don't have to.33+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.36 37-The main reason however why Flask is called a "microframework" is the idea37+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 knows the concept of41-extensions that can add this functionality into your application as if it40+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 open43+object-relational mappers, form validation, upload handling, various open44 authentication technologies and more.45 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 applications22 unmodified lines70 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 clever74+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 malicious8 unmodified lines87 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 lower92-level API should change for the unicode differences in Python3.91+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 recommend4 unmodified linesmodified:docs/installation.rst+9 added-9 removed
7 unmodified lines8 Werkzeug is a toolkit for WSGI, the standard Python interface between web9 applications and a variety of servers for both development and deployment.10 Jinja2 renders templates.11 12-So how do you get all that on your computer quickly? There are many ways13-which this section will explain, but the most kick-ass method is12+So how do you get all that on your computer quickly? There are many ways,13+as this section will explain, but the most kick-ass method is14 virtualenv, so let's look at that first.15 16 Either way, you will need Python 2.5 or higher to get started, so be sure17 to have an up to date Python 2.x installation. At the time of writing,39 unmodified lines57 $ sudo apt-get install python-virtualenv58 59 If you are on Windows and don't have the `easy_install` command, you must60 install it first. Check the :ref:`windows-easy-install` section for more61-information about how to do that. Once you have it installed, run the61+information on how to do that. Once you have it installed, run the62 same commands as above, but without the `sudo` prefix.63 64 Once you have virtualenv installed, just fire up a shell and create65 your own environment. I usually create a project folder and an `env`11 unmodified lines77 $ . env/bin/activate78 79 (Note the space between the dot and the script name. The dot means that80 this script should run in the context of the current shell. If this command81-does not work in your shell, try replacing the dot with ``source``)81+does not work in your shell, try replacing the dot with ``source``.)82 83 If you are a Windows user, the following command is for you::84 85 $ env\scripts\activate8 unmodified lines94 95 A few seconds later you are good to go.96 97 98-System Wide Installation98+System-Wide Installation99 ------------------------100 101-This is possible as well, but I do not recommend it. Just run102-`easy_install` with root rights::101+This is possible as well, though I do not recommend it. Just run102+`easy_install` with root privileges::103 104 $ sudo easy_install Flask105 106-(Run it in an Admin shell on Windows systems and without `sudo`).106+(Run it in an Admin shell on Windows systems and without `sudo`.)107 108 109 Living on the Edge110 ------------------47 unmodified lines158 to the `PATH` environment variable. To do that, right-click on the159 "Computer" icon on the Desktop or in the Start menu, and choose160 "Properties". Then, on Windows Vista and Windows 7 click on "Advanced System161 settings"; on Windows XP, click on the "Advanced" tab instead. Then click162-on the "Environment variables" button and double click on the "Path"162+on the "Environment variables" button and double-click on the "Path"163 variable in the "System variables" section. There append the path of your164 Python interpreter's Scripts folder; make sure you delimit it from165 existing values with a semicolon. Assuming you are using Python 2.6 on166 the default path, add the following value::9 unmodified linesmodified:docs/quickstart.rst+56 added-57 removed
1 unmodified line2 3 Quickstart4 ==========5 6-Eager to get started? This page gives a good introduction in how to get6+Eager to get started? This page gives a good introduction on how to get7 started with Flask. This assumes you already have Flask installed. If8 you do not, head over to the :ref:`installation` section.9 10 27 unmodified lines38 So what did that code do?39 40 1. First we imported the :class:`~flask.Flask` class. An instance of this41 class will be our WSGI application. The first argument is the name of42- the application's module. If you are using a single module (like here)43- you should use `__name__` because depending on if it's started as42+ the application's module. If you are using a single module (as in this example)43+ you should use `__name__` because depending on whether it's started as44 application or imported as module the name will be different45 (``'__main__'`` versus the actual import name). For more information46- on that, have a look at the :class:`~flask.Flask` documentation.46+ on this technique, have a look at the :class:`~flask.Flask` documentation.47 2. Next we create an instance of it. We pass it the name of the module /48 package. This is needed so that Flask knows where it should look for49 templates, static files and so on.50 3. Then we use the :meth:`~flask.Flask.route` decorator to tell Flask51- what URL should trigger our function.51+ which URL should trigger our function.52 4. The function then has a name which is also used to generate URLs to53 that particular function, and returns the message we want to display in54 the user's browser.55 5. Finally we use the :meth:`~flask.Flask.run` function to run the6 unmodified lines62 .. _public-server:63 64 .. admonition:: Externally Visible Server65 66- If you run the server you will notice that the server is only available66+ If you run the server you will notice that the server is only accessible67 from your own computer, not from any other in the network. This is the68 default because in debugging mode a user of the application can execute69- arbitrary Python code on your computer. If you have `debug` disabled70- or trust the users on your network, you can make the server publicly71- available.69+ arbitrary Python code on your computer.70 73- Just change the call of the :meth:`~flask.Flask.run` method to look74- like this::71+ If you have `debug` disabled or trust the users on your network, you can72+ make the server publicly available simply by changing the call of the73+ :meth:`~flask.Flask.run` method to look like this::74 75 app.run(host='0.0.0.0')76 77 This tells your operating system to listen on a public IP.3 unmodified lines81 ----------82 83 The :meth:`~flask.Flask.run` method is nice to start a local84 development server, but you would have to restart it manually after each86-change you do to code. That is not very nice and Flask can do better. If87-you enable the debug support the server will reload itself on code changes88-and also provide you with a helpful debugger if things go wrong.85+change to your code. That is not very nice and Flask can do better. If86+you enable debug support the server will reload itself on code changes,87+and it will also provide you with a helpful debugger if things go wrong.88 89 There are two ways to enable debugging. Either set that flag on the90 application object::91 92 app.debug = True93 app.run()94 96-Or pass it to run::95+Or pass it to `run`::96 97 app.run(debug=True)98 99 Both will have exactly the same effect.21 unmodified lines121 Routing122 -------123 124 Modern web applications have beautiful URLs. This helps people remember126-the URLs which is especially handy for applications that are used from125+the URLs, which is especially handy for applications that are used from126 mobile devices with slower network connections. If the user can directly127 go to the desired page without having to hit the index page it is more128 likely they will like the page and come back next time.129 39 unmodified lines169 170 .. admonition:: Unique URLs / Redirection Behaviour171 172 Flask's URL rules are based on Werkzeug's routing module. The idea174- behind that module is to ensure nice looking and also unique URLs based175- on behaviour Apache and earlier servers coined.173+ behind that module is to ensure nice-looking and also unique URLs based174+ on behaviour coined by Apache and earlier servers.175 176 Take these two rules::177 178 @app.route('/projects/')9 unmodified lines188 `projects` endpoint has a trailing slash. It's similar to a folder in189 that sense. Accessing it without a trailing slash will cause Flask to190 redirect to the canonical URL with the trailing slash.191 193- However in the second case the URL is defined without a slash so it192+ However, in the second case the URL is defined without a slash so it193 behaves similar to a file and accessing the URL with a trailing slash195- will be a 404 error.194+ will result in a 404 error.195 196 Why is this? This allows relative URLs to continue working if users197 access the page when they forget a trailing slash. This behaviour is198 also consistent with how Apache and other servers work. Also, the URLs200- will stay unique which helps search engines not indexing the same page199+ will stay unique which ensures search engines do not index the same page200 twice.201 202 203 .. _url-building:32 unmodified lines236 237 (This also uses the :meth:`~flask.Flask.test_request_context` method238 explained below. It basically tells Flask to think we are handling a239 request even though we are not, we are in an interactive Python shell.241-Have a look at the explanation below. :ref:`context-locals`).240+Have a look at the explanation below: :ref:`context-locals`.)241 242 Why would you want to build URLs instead of hardcoding them in your243 templates? There are three good reasons for this:244 23 unmodified lines268 show_the_login_form()269 270 If `GET` is present, `HEAD` will be added automatically for you. You271 don't have to deal with that. It will also make sure that `HEAD` requests273-are handled like the `HTTP RFC`_ (the document describing the HTTP272+are handled as the `HTTP RFC`_ (the document describing the HTTP273 protocol) demands, so you can completely ignore that part of the HTTP275-specification. Likewise as of Flask 0.6, `OPTIONS` is implemented for you276-as well automatically.274+specification. Likewise, as of Flask 0.6, `OPTIONS` is implemented for you275+automatically as well.276 277 You have no idea what an HTTP method is? Worry not, here is a quick278 introduction to HTTP methods and why they matter:279 15 unmodified lines295 296 `POST`297 The browser tells the server that it wants to *post* some new298 information to that URL and that the server must ensure the data is300- stored and only stored once. This is how HTML forms are usually301- transmitting data to the server.299+ stored and only stored once. This is how HTML forms usually300+ transmit data to the server.301 302 `PUT`303 Similar to `POST` but the server might trigger the store procedure304 multiple times by overwriting the old values more than once. Now you306- might be asking why is this useful, but there are some good reasons307- to do it this way. Consider that the connection gets lost during305+ might be asking why this is useful, but there are some good reasons306+ to do it this way. Consider that the connection is lost during307 transmission: in this situation a system between the browser and the308 server might receive the request safely a second time without breaking309 things. With `POST` that would not be possible because it must only310 be triggered once.17 unmodified lines328 329 Static Files330 ------------331 333-Dynamic web applications need static files as well. That's usually where332+Dynamic web applications also need static files. That's usually where333 the CSS and JavaScript files are coming from. Ideally your web server is334 configured to serve them for you, but during development Flask can do that335 as well. Just create a folder called `static` in your package or next to336 your module and it will be available at `/static` on the application.337 339-To generate URLs to that part of the URL, use the special ``'static'`` URL338+To generate URLs that part of the URL, use the special ``'static'`` URL339 name::340 341 url_for('static', filename='style.css')342 7 unmodified lines350 the application secure. Because of that Flask configures the `Jinja2351 <http://jinja.pocoo.org/2/>`_ template engine for you automatically.352 353 To render a template you can use the :func:`~flask.render_template`355-method. All you have to do is to provide the name of the template and the354+method. All you have to do is provide the name of the template and the355 variables you want to pass to the template engine as keyword arguments.356 Here's a simple example of how to render a template::357 358 from flask import render_template3 unmodified lines362 def hello(name=None):363 return render_template('hello.html', name=name)364 365 Flask will look for templates in the `templates` folder. So if your367-application is a module, that folder is next to that module, if it's a366+application is a module, this folder is next to that module, if it's a367 package it's actually inside your package:368 369 **Case 1**: a module::370 32 unmodified lines403 know how that works, head over to the :ref:`template-inheritance` pattern404 documentation. Basically template inheritance makes it possible to keep405 certain elements on each page (like header, navigation and footer).406 408-Automatic escaping is enabled, so if name contains HTML it will be escaped407+Automatic escaping is enabled, so if `name` contains HTML it will be escaped408 automatically. If you can trust a variable and you know that it will be410-safe HTML (because for example it came from a module that converts wiki409+safe HTML (for example because it came from a module that converts wiki410 markup to HTML) you can mark it as safe by using the411 :class:`~jinja2.Markup` class or by using the ``|safe`` filter in the412 template. Head over to the Jinja 2 documentation for more examples.413 26 unmodified lines440 For web applications it's crucial to react to the data a client sent to441 the server. In Flask this information is provided by the global442 :class:`~flask.request` object. If you have some experience with Python443 you might be wondering how that object can be global and how Flask445-manages to still be threadsafe. The answer are context locals:444+manages to still be threadsafe. The answer is context locals:445 446 447 .. _context-locals:448 9 unmodified lines458 These objects are actually proxies to objects that are local to a specific459 context. What a mouthful. But that is actually quite easy to understand.460 461 Imagine the context being the handling thread. A request comes in and the463-webserver decides to spawn a new thread (or something else, the464-underlying object is capable of dealing with other concurrency systems465-than threads as well). When Flask starts its internal request handling it462+web server decides to spawn a new thread (or something else, the463+underlying object is capable of dealing with concurrency systems other464+than threads). When Flask starts its internal request handling it465 figures out that the current thread is the active context and binds the466 current application and the WSGI environments to that context (thread).468-It does that in an intelligent way that one application can invoke another467+It does that in an intelligent way so that one application can invoke another468 application without breaking.469 470 So what does this mean to you? Basically you can completely ignore that472-this is the case unless you are doing something like unittesting. You473-will notice that code that depends on a request object will suddenly break471+this is the case unless you are doing something like unit testing. You472+will notice that code which depends on a request object will suddenly break473 because there is no request object. The solution is creating a request474 object yourself and binding it to the context. The easiest solution for476-unittesting is by using the :meth:`~flask.Flask.test_request_context`475+unit testing is to use the :meth:`~flask.Flask.test_request_context`476 context manager. In combination with the `with` statement it will bind a477 test request so that you can interact with it. Here is an example::478 479 from flask import request198 unmodified lines678 2. If it's a string, a response object is created with that data and the679 default parameters.680 3. If a tuple is returned the response object is created by passing the681 tuple as arguments to the response object's constructor.683-4. If neither of that works, Flask will assume the return value is a684- valid WSGI application and converts that into a response object.682+4. If none of that works, Flask will assume the return value is a683+ valid WSGI application and convert that into a response object.684 685 If you want to get hold of the resulting response object inside the view686 you can use the :func:`~flask.make_response` function.687 21 unmodified lines709 710 Sessions711 --------712 714-Besides the request object there is also a second object called715-:class:`~flask.session` that allows you to store information specific to a713+In addition to the request object there is also a second object called714+:class:`~flask.session` which allows you to store information specific to a715 user from one request to the next. This is implemented on top of cookies716 for you and signs the cookies cryptographically. What this means is that717 the user could look at the contents of your cookie but not modify it,718 unless they know the secret key used for signing.31 unmodified lines750 751 # set the secret key. keep this really secret:752 app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'753 755-The here mentioned :func:`~flask.escape` does escaping for you if you are756-not using the template engine (like in this example).754+The :func:`~flask.escape` mentioned here does escaping for you if you are755+not using the template engine (as in this example).756 757 .. admonition:: How to generate good secret keys758 760- The problem with random is that it's hard to judge what random is. And759+ The problem with random is that it's hard to judge what is truly random. And760 a secret key should be as random as possible. Your operating system761 has ways to generate pretty random stuff based on a cryptographic762 random generator which can be used to get such a key:763 9 unmodified lines773 Good applications and user interfaces are all about feedback. If the user774 does not get enough feedback they will probably end up hating the775 application. Flask provides a really simple way to give feedback to a776 user with the flashing system. The flashing system basically makes it778-possible to record a message at the end of a request and access it next779-request and only next request. This is usually combined with a layout780-template that does this.777+possible to record a message at the end of a request and access it on the next778+(and only the next) request. This is usually combined with a layout779+template to expose the message.780 781 To flash a message use the :func:`~flask.flash` method, to get hold of the782 messages you can use :func:`~flask.get_flashed_messages` which is also783 available in the templates. Check out the :ref:`message-flashing-pattern`4 unmodified lines788 789 .. versionadded:: 0.3790 791 Sometimes you might be in a situation where you deal with data that793-should be correct, but actually is not. For example you may have some client794-side code that sends an HTTP request to the server but it's obviously795-malformed. This might be caused by a user tempering with the data, or the796-client code failing. Most of the time, it's okay to reply with ``400 Bad792+should be correct, but actually is not. For example you may have some client-side793+code that sends an HTTP request to the server but it's obviously794+malformed. This might be caused by a user tampering with the data, or the795+client code failing. Most of the time it's okay to reply with ``400 Bad796 Request`` in that situation, but sometimes that won't do and the code has797 to continue working.798 799 You may still want to log that something fishy happened. This is where24 unmodified lines