more editorial work
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Ori Livneh · committed by Ron DuPlain · parent 593b003 · Browse files · 1 file·+77 added−78 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−78 removed
- other:+77 added−78 removed
Provenance
- Commit
df19ee9- Tree
a0bfebb- Author
Ori Livneh <ori.livneh@gmail.com>- Committer
Ron DuPlain <ron.duplain@gmail.com>- Parent
593b003
1 file changed+77 added−78 removed
modified:docs/quickstart.rst+77 added-78 removed
1 unmodified line2 3 Quickstart4 ==========5 6-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.6+Eager to get started? This page gives a good introduction to Flask. It7+assumes you already have Flask installed. If you do not, head over to the8+:ref:`installation` section.9 10 11 A Minimal Application12 ---------------------9 unmodified lines22 23 if __name__ == '__main__':24 app.run()25 26-Just save it as `hello.py` or something similar and run it with your27-Python interpreter. Make sure to not call your application `flask.py`28-because this would conflict with Flask itself.26+Just save it as `hello.py` (or something similar) and run it with your Python27+interpreter. Make sure to not call your application `flask.py` because this28+would conflict with Flask itself.29 30 ::31 32 $ python hello.py33 * Running on http://127.0.0.1:5000/34 35-Head over to `http://127.0.0.1:5000/ <http://127.0.0.1:5000/>`_, you should36-see your hello world greeting.35+Now head over to `http://127.0.0.1:5000/ <http://127.0.0.1:5000/>`_, and you36+should see your hello world greeting.37 38 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 (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 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- 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 the56- local server with our application. The ``if __name__ == '__main__':``57- makes sure the server only runs if the script is executed directly from58- the Python interpreter and not used as imported module.42+ the application's module. If you are using a single module (as in this43+ example), you should use `__name__` because depending on if it's started as44+ application or imported as module the name will be different (``'__main__'``45+ versus the actual import name). For more information, have a look at the46+ :class:`~flask.Flask` documentation.47+2. Next we create an instance of this class. We pass it the name of the module48+ or package. This is needed so that Flask knows where to look for templates,49+ static files, and so on.50+3. We then use the :meth:`~flask.Flask.route` decorator to tell Flask what URL51+ should trigger our function.52+4. The function is given a name which is also used to generate URLs for that53+ particular function, and returns the message we want to display in the54+ user's browser.55+5. Finally we use the :meth:`~flask.Flask.run` function to run the local server56+ with our application. The ``if __name__ == '__main__':`` makes sure the57+ server only runs if the script is executed directly from the Python58+ interpreter and not used as imported module.59 60 To stop the server, hit control-C.61 62 .. _public-server:10 unmodified lines73 :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.77+ This tells your operating system to listen on all public IPs.78 79 80 Debug Mode81 ----------9 unmodified lines91 92 app.debug = True93 app.run()94 95-Or pass it to `run`::95+Or pass it as a parameter to run::96 97 app.run(debug=True)98 99-Both will have exactly the same effect.99+Both methods have the exact same effect.100 101 .. admonition:: Attention102 103 Even though the interactive debugger does not work in forking environments104 (which makes it nearly impossible to use on production servers), it still105- allows the execution of arbitrary code. That makes it a major security106- risk and therefore it **must never be used on production machines**.105+ allows the execution of arbitrary code. This makes it a major security risk106+ and therefore it **must never be used on production machines**.107 108 Screenshot of the debugger in action:109 110 .. image:: _static/debugger.png2 unmodified lines113 :alt: screenshot of debugger in action114 115 .. admonition:: Working With Other Debuggers116 117- Debuggers interfere with each other. 118- That said, you may still wish to use the debugger in a tool of your choice. 117+ Debuggers interfere with each other.118+ That said, you may still wish to use the debugger in a tool of your choice.119 Flask provides the following options to manage the debug process:120 121 * ``debug`` - whether to enable debug mode and catch exceptinos122 * ``use_debugger`` - whether to use the internal Flask debugger123 * ``use_reloader`` - whether to reload and fork the process on exception124 125- ``debug`` must be True (i.e., exceptions must caught) in order for the 125+ ``debug`` must be True (i.e., exceptions must caught) in order for the126 other two options to have any value.127 128- If you're using Aptana/Eclipse for debugging you'll need to set both 128+ If you're using Aptana/Eclipse for debugging you'll need to set both129 ``use_debugger`` and ``use_reloader`` to False.130 131- A possible useful pattern for configuration is to set the following in your 131+ A possible useful pattern for configuration is to set the following in your132 config.yaml (change the block as approriate for your application, of course)::133 134 FLASK:135 DEBUG: True22 unmodified lines158 mobile devices with slower network connections. If the user can directly159 go to the desired page without having to hit the index page it is more160 likely they will like the page and come back next time.161 162-As you have seen above, the :meth:`~flask.Flask.route` decorator is used163-to bind a function to a URL. Here are some basic examples::162+As you have seen above, the :meth:`~flask.Flask.route` decorator is used to163+bind a function to a URL. Here are some basic examples::164 165 @app.route('/')166 def index():167 return 'Index Page'1 unmodified line169 @app.route('/hello')170 def hello():171 return 'Hello World'172 173-But there is more to it! You can make certain parts of the URL dynamic174-and attach multiple rules to a function.173+But there is more to it! You can make certain parts of the URL dynamic and174+attach multiple rules to a function.175 176 Variable Rules177 ``````````````178 179 To add variable parts to a URL you can mark these special sections as180-``<variable_name>``. Such a part is then passed as keyword argument to181-your function. Optionally a converter can be specified by specifying a182-rule with ``<converter:variable_name>``. Here are some nice examples::180+``<variable_name>``. Such a part is then passed as keyword argument to your181+function. Optionally a converter can be specified by specifying a rule with182+``<converter:variable_name>``. Here are some nice examples::183 184 @app.route('/user/<username>')185 def show_user_profile(username):186 # show the user profile for that user13 unmodified lines200 =========== ===========================================201 202 .. admonition:: Unique URLs / Redirection Behaviour203 204- Flask's URL rules are based on Werkzeug's routing module. The idea205- behind that module is to ensure nice-looking and also unique URLs based206- on behaviour coined by Apache and earlier servers.204+ Flask's URL rules are based on Werkzeug's routing module. The idea behind205+ that module is to ensure beautiful and unique also unique URLs based on206+ precedents laid down by Apache and earlier HTTP servers.207 208 Take these two rules::209 210 @app.route('/projects/')3 unmodified lines214 @app.route('/about')215 def about():216 return 'The about page'217 218- They look rather similar, the difference is the trailing slash in the219- URL *definition*. In the first case, the canonical URL for the220- `projects` endpoint has a trailing slash. It's similar to a folder in221- that sense. Accessing it without a trailing slash will cause Flask to222- redirect to the canonical URL with the trailing slash.218+ Though they look rather similar, they differ in their use of the trailing219+ slash in the URL *definition*. In the first case, the canonical URL for the220+ `projects` endpoint has a trailing slash. In that sense, it is similar to221+ a folder on a file system. Accessing it without a trailing slash will cause222+ Flask to redirect to the canonical URL with the trailing slash.223 224- However, in the second case the URL is defined without a slash so it225- behaves similar to a file and accessing the URL with a trailing slash226- will result in a 404 error.224+ In the second case, however, the URL is defined without a trailing slash,225+ rather like the pathname of a file on UNIX-like systems. Accessing the URL226+ with a trailing slash will produce a 404 "Not Found" error.227 228- Why is this? This allows relative URLs to continue working if users229- access the page when they forget a trailing slash. This behaviour is230- also consistent with how Apache and other servers work. Also, the URLs231- will stay unique which ensures search engines do not index the same page232- twice.228+ This behavior allows relative URLs to continue working if users access the229+ page when they forget a trailing slash, consistent with how with how Apache230+ and other servers work. Also, the URLs will stay unique, which helps search231+ engines avoid indexing the same page twice.232 233 234 .. _url-building:235 236 URL Building237 ````````````238 240-If it can match URLs, can it also generate them? Of course it can. To239+If it can match URLs, can Flask also generate them? Of course it can. To240 build a URL to a specific function you can use the :func:`~flask.url_for`242-function. It accepts the name of the function as first argument and a243-number of keyword arguments, each corresponding to the variable part of244-the URL rule. Unknown variable parts are appended to the URL as query245-parameter. Here are some examples:241+function. It accepts the name of the function as first argument and a number242+of keyword arguments, each corresponding to the variable part of the URL rule.243+Unknown variable parts are appended to the URL as query parameters. Here are244+some examples:245 246 >>> from flask import Flask, url_for247 >>> app = Flask(__name__)248 >>> @app.route('/')15 unmodified lines264 /login265 /login?next=/266 /user/John%20Doe267 269-(This also uses the :meth:`~flask.Flask.test_request_context` method270-explained below. It basically tells Flask to think we are handling a271-request even though we are not, we are in an interactive Python shell.272-Have a look at the explanation below: :ref:`context-locals`.)268+(This also uses the :meth:`~flask.Flask.test_request_context` method, explained269+below. It tells Flask to behave as though it is handling a request, even270+though were are interacting with it through a Python shell. Have a look at the271+explanation below. :ref:`context-locals`).272 274-Why would you want to build URLs instead of hardcoding them in your273+Why would you want to build URLs instead of hard-coding them into your274 templates? There are three good reasons for this:275 277-1. reversing is often more descriptive than hardcoding the URLs. Also and278- more importantly you can change URLs in one go without having to change279- the URLs all over the place.276+1. Reversing is often more descriptive than hard-coding the URLs. More277+ importantly, it allows you to change URLs in one go, without having to278+ remember to change URLs all over the place.279 2. URL building will handle escaping of special characters and Unicode281- data transparently for you, you don't have to deal with that.282-3. If your application is placed outside the URL root (so say in283- ``/myapplication`` instead of ``/``), :func:`~flask.url_for` will284- handle that properly for you.280+ data transparently for you, so you don't have to deal with them.281+3. If your application is placed outside the URL root (say, in282+ ``/myapplication`` instead of ``/``), :func:`~flask.url_for` will handle283+ that properly for you.284 285 286 HTTP Methods287 ````````````288 290-HTTP (the protocol web applications are speaking) knows different methods291-to access URLs. By default a route only answers to `GET` requests, but292-that can be changed by providing the `methods` argument to the289+HTTP (the protocol web applications are speaking) knows different methods for290+accessing URLs. By default, a route only answers to `GET` requests, but that291+can be changed by providing the `methods` argument to the292 :meth:`~flask.Flask.route` decorator. Here are some examples::293 294 @app.route('/login', methods=['GET', 'POST'])295 def login():559 unmodified lines