Merge branch 'master' of github.com:mitsuhiko/flask
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parents 405c299, 325b960 · Browse files · 22 files·+56 added−51 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
22 files+56 added−51 removed
- other:+56 added−51 removed
Provenance
- Commit
5ecf01d- Tree
9861053- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent 1
405c299- Parent 2
325b960
22 files changed+56 added−51 removed
modified:docs/deploying/cgi.rst+1 added-1 removed
36 unmodified lines37 Server Setup38 ------------39 40 Usually there are two ways to configure the server. Either just copy the41-`.cgi` into a `cgi-bin` (and use `mod_rerwite` or something similar to41+`.cgi` into a `cgi-bin` (and use `mod_rewrite` or something similar to42 rewrite the URL) or let the server point to the file directly.43 44 In Apache for example you can put a like like this into the config:45 5 unmodified linesmodified:docs/deploying/fastcgi.rst+1 added-1 removed
121 unmodified lines122 $ su www-data123 $ cd /var/www/yourapplication124 $ python application.fcgi125 Traceback (most recent call last):126- File "yourapplication.fcg", line 4, in <module>126+ File "yourapplication.fcgi", line 4, in <module>127 ImportError: No module named yourapplication128 129 In this case the error seems to be "yourapplication" not being on the python130 path. Common problems are:9 unmodified linesmodified:docs/deploying/mod_wsgi.rst+2 added-2 removed
91 unmodified lines92 .. _installation instructions: http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide93 .. _virtual python: http://pypi.python.org/pypi/virtualenv94 .. _mod_wsgi wiki: http://code.google.com/p/modwsgi/wiki/95 96-Toubleshooting97---------------96+Troubleshooting97+---------------98 99 If your application does not run, follow this guide to troubleshoot:100 101 **Problem:** application does not run, errorlog shows SystemExit ignored65 unmodified linesmodified:docs/deploying/others.rst+2 added-2 removed
67 unmodified lines68 If you deploy your application behind an HTTP proxy you will need to69 rewrite a few headers in order for the application to work. The two70 problematic values in the WSGI environment usually are `REMOTE_ADDR` and71 `HTTP_HOST`. Werkzeug ships a fixer that will solve some common setups,72-but you might want to write your own WSGI middlware for specific setups.72+but you might want to write your own WSGI middleware for specific setups.73 74 The most common setup invokes the host being set from `X-Forwarded-Host`75-and the remote address from `X-Forwared-For`::75+and the remote address from `X-Forward-For`::76 77 from werkzeug.contrib.fixers import ProxyFix78 app.wsgi_app = ProxyFix(app.wsgi_app)79 19 unmodified linesmodified:docs/patterns/errorpages.rst+1 added-1 removed
31 unmodified lines32 resources that previously existed and got deleted answer with 41033 instead of 404. If you are not deleting documents permanently from34 the database but just mark them as deleted, do the user a favour and35 use the 410 code instead and display a message that what he was36- looking for was deleted for all ethernity.36+ looking for was deleted for all eternity.37 38 *500 Internal Server Error*39 Usually happens on programming errors or if the server is overloaded.40 A terrible good idea to have a nice page there, because your37 unmodified linesmodified:docs/patterns/fileuploads.rst+3 added-3 removed
39 unmodified lines40 41 Why do we limit the extensions that are allowed? You probably don't want42 your users to be able to upload everything there if the server is directly43 sending out the data to the client. That way you can make sure that users44-are not able to upload HTML files that would cause XSS problems. Also45-make sure to disallow `.php` files if the server executes them, but who46-has PHP installed on his server, right? :)44+are not able to upload HTML files that would cause XSS problems (see45+:ref:`xss`). Also make sure to disallow `.php` files if the server46+executes them, but who has PHP installed on his server, right? :)47 48 Next the functions that check if an extension is valid and that uploads49 the file and redirects the user to the URL for the uploaded file::50 130 unmodified linesmodified:docs/patterns/flashing.rst+2 added-2 removed
28 unmodified lines29 if request.form['username'] != 'admin' or \30 request.form['password'] != 'secret':31 error = 'Invalid credentials'32 else:33- flash('You were sucessfully logged in')33+ flash('You were successfully logged in')34 return redirect(url_for('index'))35 return render_template('login.html', error=error)36 37 And here the ``layout.html`` template which does the magic:61 unmodified lines99 flash(u'Invalid password provided', 'error')100 101 Inside the template you then have to tell the102 :func:`~flask.get_flashed_messages` function to also return the103-categories. The loop looks slighty different in that situation then:103+categories. The loop looks slightly different in that situation then:104 105 .. sourcecode:: html+jinja106 107 {% with messages = get_flashed_messages(with_categories=true) %}12 unmodified linesmodified:docs/patterns/lazyloading.rst+1 added-1 removed
98 unmodified lines99 url('/', 'views.index')100 url('/user/<username>', 'views.user')101 102 One thing to keep in mind is that before and after request handlers have103-to be in a file that is imported upfront to work propery on the first103+to be in a file that is imported upfront to work properly on the first104 request. The same goes for any kind of remaining decorator.modified:docs/patterns/mongokit.rst+1 added-1 removed
76 unmodified lines77 validator for the maximum character length and uses a special MongoKit feature78 called `use_dot_notation`. Per default MongoKit behaves like a python79 dictionary but with `use_dot_notation` set to `True` you can use your80 documents like you use models in nearly any other ORM by using dots to81-seperate between attributes.81+separate between attributes.82 83 You can insert entries into the database like this:84 85 >>> from yourapplication.database import connection59 unmodified linesmodified:docs/patterns/packages.rst+6 added-1 removed
160 unmodified lines161 from yourapplication.views.admin import admin162 from yourapplication.views.frontend import frontend163 164 app = Flask(__name__)165- app.register_module(admin)165+ app.register_module(admin, url_prefix='/admin')166 app.register_module(frontend)167 168+We register the modules with the app so that it can add them to the169+URL map for our application. Note the prefix argument to the admin170+module: by default when we register a module, that module's end-points171+will be registered on `/` unless we specify this argument.172+173 So what is different when working with modules? It mainly affects URL174 generation. Remember the :func:`~flask.url_for` function? When not175 working with modules it accepts the name of the function as first176 argument. This first argument is called the "endpoint". When you are110 unmodified linesmodified:docs/patterns/sqlite3.rst+1 added-1 removed
59 unmodified lines60 print the_username, 'has the id', user['user_id']61 62 To pass variable parts to the SQL statement, use a question mark in the63 statement and pass in the arguments as a list. Never directly add them to64-the SQL statement with string formattings because this makes it possible64+the SQL statement with string formatting because this makes it possible65 to attack the application using `SQL Injections66 <http://en.wikipedia.org/wiki/SQL_injection>`_.67 68 Initial Schemas19 unmodified linesmodified:docs/patterns/viewdecorators.rst+1 added-1 removed
87 unmodified lines88 return rv89 return decorated_function90 return decorator91 92-Notice that this assumes an instanciated `cache` object is available, see92+Notice that this assumes an instantiated `cache` object is available, see93 :ref:`caching-pattern` for more information.94 95 96 Templating Decorator51 unmodified linesmodified:docs/tutorial/setup.rst+1 added-1 removed
74 unmodified lines75 focus on that a little later. First we should get the database working.76 77 .. admonition:: Externally Visible Server78 79- Want your server to be publically available? Check out the79+ Want your server to be publicly available? Check out the80 :ref:`externally visible server <public-server>` section for more81 information.82 83 Continue with :ref:`tutorial-dbinit`.modified:docs/api.rst+2 added-2 removed
419 unmodified lines420 Notes On Proxies421 ----------------422 423 Some of the objects provided by Flask are proxies to other objects. The424-reason behind this is, that these proxies are shared between threads and424+reason behind this is that these proxies are shared between threads and425 they have to dispatch to the actual object bound to a thread behind the426 scenes as necessary.427 428 Most of the time you don't have to care about that, but there are some429 exceptions where it is good to know that this object is an actual proxy:430 431 - The proxy objects do not fake their inherited types, so if you want to432 perform actual instance checks, you have to do that on the instance433- that433+ that is being proxied (see `_get_current_object` below).434 - if the object reference is important (so for example for sending435 :ref:`signals`)436 437 If you need to get access to the underlying object that is proxied, you4 unmodified linesmodified:docs/becomingbig.rst+1 added-1 removed
8 unmodified lines9 10 Flask is powered by Werkzeug and Jinja2, two libraries that are in use at11 a number of large websites out there and all Flask does is bring those12 two together. Being a microframework Flask does not do much more than13-combinding existing libraries - there is not a lot of code involved.13+combining existing libraries - there is not a lot of code involved.14 What that means for large applications is that it's very easy to take the15 code from Flask and put it into a new module within the applications and16 expand on that.17 71 unmodified linesmodified:docs/config.rst+2 added-2 removed
59 unmodified lines60 :class:`datetime.timedelta` object.61 ``USE_X_SENDFILE`` enable/disable x-sendfile62 ``LOGGER_NAME`` the name of the logger63 ``SERVER_NAME`` the name of the server. Required for64- subdomain support (eg: ``'localhost'``)64+ subdomain support (e.g.: ``'localhost'``)65 ``MAX_CONTENT_LENGTH`` If set to a value in bytes, Flask will66 reject incoming requests with a67 content length greater than this by68 returning a 413 status code.152 unmodified lines221 code at all. If you are working often on different projects you can222 even create your own script for sourcing that activates a virtualenv223 and exports the development configuration for you.224 - Use a tool like `fabric`_ in production to push code and225- configurations sepearately to the production server(s). For some225+ configurations separately to the production server(s). For some226 details about how to do that, head over to the :ref:`deploy` pattern.227 228 .. _fabric: http://fabfile.org/modified:docs/extensiondev.rst+1 added-1 removed
151 unmodified lines152 There are two recommended ways for an extension to initialize:153 154 initialization functions:155 If your extension is called `helloworld` you might have a function156- called ``init_helloworld(app[, extra_args])`` that initalizes the156+ called ``init_helloworld(app[, extra_args])`` that initializes the157 extension for that application. It could attach before / after158 handlers etc.159 160 classes:167 unmodified linesmodified:docs/license.rst+1 added-1 removed
2 unmodified lines3 4 Flask is licensed under a three clause BSD License. It basically means:5 do whatever you want with it as long as the copyright in Flask sticks6 around, the conditions are not modified and the disclaimer is present.7-Furthermore you must not use the names of the authors to promote derivates7+Furthermore you must not use the names of the authors to promote derivatives8 of the software without written consent.9 10 The full license text can be found below (:ref:`flask-license`). For the11 documentation and artwork different licenses apply.37 unmodified linesmodified:docs/security.rst+21 added-21 removed
60 unmodified lines61 Another big problem is CSRF. This is a very complex topic and I won't62 outline it here in detail just mention what it is and how to theoretically63 prevent it.64 65-So if your authentication information is stored in cookies you have66-implicit state management. By that I mean that the state of "being logged67-in" is controlled by a cookie and that cookie is sent with each request to68-a page. Unfortunately that really means "each request" so also requests69-triggered by 3rd party sites. If you don't keep that in mind some people70-might be able to trick your application's users with social engineering to71-do stupid things without them knowing.65+If your authentication information is stored in cookies, you have implicit66+state management. The state of "being logged in" is controlled by a67+cookie, and that cookie is sent with each request to a page.68+Unfortunately that includes requests triggered by 3rd party sites. If you69+don't keep that in mind, some people might be able to trick your70+application's users with social engineering to do stupid things without71+them knowing.72 73 Say you have a specific URL that, when you sent `POST` requests to will74 delete a user's profile (say `http://example.com/user/delete`). If an75 attacker now creates a page that sends a post request to that page with76-some JavaScript he just has to trick some users to that page and their77-profiles will end up being deleted.76+some JavaScript he just has to trick some users to load that page and77+their profiles will end up being deleted.78 79-Imagine you would run Facebook with millions of concurrent users and80-someone would send out links to images of little kittens. When a user81-would go to that page their profiles would get deleted while they are79+Imagine you were to run Facebook with millions of concurrent users and80+someone would send out links to images of little kittens. When users81+would go to that page, their profiles would get deleted while they are82 looking at images of fluffy cats.83 84-So how can you prevent yourself from that? Basically for each request85-that modifies content on the server you would have to either use a86-one-time token and store that in the cookie **and** also transmit it with87-the form data. After recieving the data on the server again you would88-then have to compare the two tokens and ensure they are equal.84+How can you prevent that? Basically for each request that modifies85+content on the server you would have to either use a one-time token and86+store that in the cookie **and** also transmit it with the form data.87+After receiving the data on the server again, you would then have to88+compare the two tokens and ensure they are equal.89 90-Why does not Flask do that for you? The ideal place for this to happen is91-the form validation framework which does not exist in Flask.90+Why does Flask not do that for you? The ideal place for this to happen is91+the form validation framework, which does not exist in Flask.92 93 .. _json-security:94 95 JSON Security14 unmodified lines110 generate JSON.111 112 So what is the issue and how to avoid it? The problem are arrays at113 toplevel in JSON. Imagine you send the following data out in a JSON114-request. Say that's exporting the names and email adresses of all your115-friends for a part of the userinterface that is written in JavaScript.114+request. Say that's exporting the names and email addresses of all your115+friends for a part of the user interface that is written in JavaScript.116 Not very uncommon:117 118 .. sourcecode:: javascript119 49 unmodified linesmodified:docs/styleguide.rst+3 added-3 removed
70 unmodified lines71 --------------------------72 73 General whitespace rules:74 - No whitespace for unary operators that are not words75- (eg: ``-``, ``~`` etc.) as well on the inner side of parentheses.75+ (e.g.: ``-``, ``~`` etc.) as well on the inner side of parentheses.76 - Whitespace is placed between binary operators.77 78 Good::79 70 unmodified lines150 151 Docstring conventions:152 All docstrings are formatted with reStructuredText as understood by153 Sphinx. Depending on the number of lines in the docstring, they are154- layed out differently. If it's just one line, the closing triple154+ laid out differently. If it's just one line, the closing triple155 quote is on the same line as the opening, otherwise the text is on156 the same line as the opening quote and the triple quote that closes157 the string on its own line::158 2 unmodified lines161 162 163 def bar():164 """This is a longer docstring with so much information in there165- that it spans three lines. In this case the closing tripple quote165+ that it spans three lines. In this case the closing triple quote166 is on its own line.167 """168 169 Module header:31 unmodified linesmodified:docs/templating.rst+1 added-1 removed
142 unmodified lines143 <p>autoescaping is disabled here144 <p>{{ will_not_be_escaped }}145 {% endautoescape %}146 147-Whenever you do this, please be very cautious about the varibles you are147+Whenever you do this, please be very cautious about the variables you are148 using in this block.149 150 Registering Filters151 -------------------37 unmodified linesmodified:docs/upgrading.rst+1 added-1 removed
50 unmodified lines51 order of after-request handlers. Previously they were called in the order52 of the registration, now they are called in reverse order. This change53 was made so that Flask behaves more like people expected it to work and54 how other systems handle request pre- and postprocessing. If you55-dependend on the order of execution of post-request functions, be sure to55+depend on the order of execution of post-request functions, be sure to56 change the order.57 58 Another change that breaks backwards compatibility is that context59 processors will no longer override values passed directly to the template78 unmodified lines