Skip to content
Myr

minor revision of documentation.

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

authored by bagratte · committed by Markus Unterwaditzer · parent e0a8fd3 · Browse files · 13 files+32 added−37 removed
This commit

State

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

Diff stats

13 files+32 added−37 removed

  • other:+32 added−37 removed

13 files+32 added−37 removed

modified:docs/deploying/mod_wsgi.rst+1 added-1 removed
141 unmodified lines
142143If your application does not run, follow this guide to troubleshoot:144145**Problem:** application does not run, errorlog shows SystemExit ignored146 You have a ``app.run()`` call in your application file that is not146 You have an ``app.run()`` call in your application file that is not147 guarded by an ``if __name__ == '__main__':`` condition. Either148 remove that :meth:`~flask.Flask.run` call from the file and move it149 into a separate :file:`run.py` file or put it into such an if block.150
67 unmodified lines
modified:docs/deploying/uwsgi.rst-6 removed
29 unmodified lines
30.. sourcecode:: text3132 $ uwsgi -s /tmp/uwsgi.sock --manage-script-name --mount /yourapplication=myapp:app3334Or, if you prefer:3536.. sourcecode:: text3738 $ uwsgi -s /tmp/uwsgi.sock --manage-script-name --mount /yourapplication=myapp:app3934The ``--manage-script-name`` will move the handling of ``SCRIPT_NAME`` to35uwsgi, since its smarter about that. It is used together with the ``--mount``36directive which will make requests to ``/yourapplication`` be directed to37``myapp:app``, where ``myapp`` refers to the name of the file of your flask
33 unmodified lines
modified:docs/patterns/appdispatch.rst+7 added-7 removed
2 unmodified lines
3Application Dispatching4=======================56Application dispatching is the process of combining multiple Flask7applications on the WSGI level. You can not only combine Flask8applications into something larger but any WSGI application. This would9even allow you to run a Django and a Flask application in the same10interpreter side by side if you want. The usefulness of this depends on11how the applications work internally.7applications on the WSGI level. You can combine not only Flask8applications but any WSGI application. This would allow you to run a9Django and a Flask application in the same interpreter side by side if10you want. The usefulness of this depends on how the applications work11internally.1213The fundamental difference from the :ref:`module approach14<larger-applications>` is that in this case you are running the same or15different Flask applications that are entirely isolated from each other.
14 unmodified lines
30Note that :func:`run_simple <werkzeug.serving.run_simple>` is not intended for31use in production. Use a :ref:`full-blown WSGI server <deployment>`.3233In order to use the interactive debugger, debugging must be enabled both on34the application and the simple server, here is the "hello world" example with34the application and the simple server. Here is the "hello world" example with35debugging and :func:`run_simple <werkzeug.serving.run_simple>`::3637 from flask import Flask38 from werkzeug.serving import run_simple
16 unmodified lines
55If you have entirely separated applications and you want them to work next56to each other in the same Python interpreter process you can take57advantage of the :class:`werkzeug.wsgi.DispatcherMiddleware`. The idea58here is that each Flask application is a valid WSGI application and they59are combined by the dispatcher middleware into a larger one that59are combined by the dispatcher middleware into a larger one that is60dispatched based on prefix.6162For example you could have your main application run on ``/`` and your63backend interface on ``/backend``::
125 unmodified lines
modified:docs/patterns/deferredcallbacks.rst+3 added-3 removed
54 unmodified lines
5556A Practical Example57-------------------5859Now we can easily at any point in time register a function to be called at60the end of this particular request. For example you can remember the61current language of the user in a cookie in the before-request function::59At any time during a request, we can register a function to be called at the60end of the request. For example you can remember the current language of the61user in a cookie in the before-request function::6263 from flask import request6465 @app.before_request
8 unmodified lines
modified:docs/tutorial/dbinit.rst+2 added-2 removed
36 unmodified lines
37 print 'Initialized the database.'3839The ``app.cli.command()`` decorator registers a new command with the40:command:`flask` script. When the command executes, Flask will automatically41create a application context for us bound to the right application.41create an application context for us bound to the right application.42Within the function, we can then access :attr:`flask.g` and other things as43we would expect. When the script ends, the application context tears down44and the database connection is released.4546We want to keep an actual functions around that initializes the database,46We want to keep an actual function around that initializes the database,47though, so that we can easily create databases in unit tests later on. (For48more information see :ref:`testing`.)4950The :func:`~flask.Flask.open_resource` method of the application object
22 unmodified lines
modified:docs/tutorial/views.rst+3 added-3 removed
10 unmodified lines
1112This view shows all the entries stored in the database. It listens on the13root of the application and will select title and text from the database.14The one with the highest id (the newest entry) will be on top. The rows15returned from the cursor look a bit like tuples because we are using15returned from the cursor look a bit like dictionaries because we are using16the :class:`sqlite3.Row` row factory.1718The view function will pass the entries as dictionaries to the19:file:`show_entries.html` template and return the rendered one::18The view function will pass the entries to the :file:`show_entries.html`19template and return the rendered one::2021 @app.route('/')22 def show_entries():23 db = get_db()
75 unmodified lines
modified:docs/appcontext.rst+2 added-2 removed
24 unmodified lines
25- any code can get hold of these objects at any time.2627There is a third state which is sitting in between a little bit.28Sometimes you are dealing with an application in a way that is similar to29how you interact with applications during request handling just that there30is no request active. Consider for instance that you're sitting in an29how you interact with applications during request handling; just that there30is no request active. Consider, for instance, that you're sitting in an31interactive Python shell and interacting with the application, or a32command line application.3334The application context is what powers the :data:`~flask.current_app`
99 unmodified lines
modified:docs/config.rst+1 added-1 removed
328 unmodified lines
329there are alternative ways as well. For example you could use imports or330subclassing.331332What is very popular in the Django world is to make the import explicit in333the config file by adding an ``from yourapplication.default_settings333the config file by adding ``from yourapplication.default_settings334import *`` to the top of the file and then overriding the changes by hand.335You could also inspect an environment variable like336``YOURAPPLICATION_MODE`` and set that to `production`, `development` etc337and import different hardcoded files based on that.
126 unmodified lines
modified:docs/errorhandling.rst+6 added-5 removed
57 unmodified lines
58:exc:`~werkzeug.exceptions.BadRequest` from the example and their HTTP codes59are interchangeable when handed to the registration methods or decorator60(``BadRequest.code == 400``).6162You are however not limited to a :exc:`~werkzeug.exceptions.HTTPException`63or its code but can register a handler for every exception class you like.62You are however not limited to :exc:`~werkzeug.exceptions.HTTPException`63or HTTP status codes but can register a handler for every exception class you64like.6566.. versionchanged:: 1.06767 Errorhandlers are now prioritized by specifity instead of the order they're68 registered in.68 Errorhandlers are now prioritized by specificity of the exception classes69 they are registered for instead of the order they are registered in.7071Handling72````````7374Once an exception instance is raised, its class hierarchy is traversed,75and searched for in the exception classes for which handlers are registered.76The most specific handler is selected.7777E.g. if a instance of :exc:`ConnectionRefusedError` is raised, and a handler78E.g. if an instance of :exc:`ConnectionRefusedError` is raised, and a handler79is registered for :exc:`ConnectionError` and :exc:`ConnectionRefusedError`,80the more specific :exc:`ConnectionRefusedError` handler is called on the81exception instance, and its response is shown to the user.82
271 unmodified lines
modified:docs/htmlfaq.rst+1 added-1 removed
28 unmodified lines
29the (X)HTML generation on the web is based on non-XML template engines30(such as Jinja, the one used in Flask) which do not protect you from31accidentally creating invalid XHTML. There are XML based template engines,32such as Kid and the popular Genshi, but they often come with a larger33runtime overhead and, are not as straightforward to use because they have33runtime overhead and are not as straightforward to use because they have34to obey XML rules.3536The majority of users, however, assumed they were properly using XHTML.37They wrote an XHTML doctype at the top of the document and self-closed all
170 unmodified lines
modified:docs/quickstart.rst+1 added-1 removed
319 unmodified lines
320You have no idea what an HTTP method is? Worry not, here is a quick321introduction to HTTP methods and why they matter:322323The HTTP method (also often called "the verb") tells the server what the324clients wants to *do* with the requested page. The following methods are324client wants to *do* with the requested page. The following methods are325very common:326327``GET``328 The browser tells the server to just *get* the information stored on
566 unmodified lines
modified:docs/signals.rst+3 added-3 removed
17 unmodified lines
18more. Also keep in mind that signals are intended to notify subscribers19and should not encourage subscribers to modify data. You will notice that20there are signals that appear to do the same thing like some of the21builtin decorators do (eg: :data:`~flask.request_started` is very similar22to :meth:`~flask.Flask.before_request`). There are however difference in23how they work. The core :meth:`~flask.Flask.before_request` handler for24example is executed in a specific order and is able to abort the request22to :meth:`~flask.Flask.before_request`). However, there are differences in23how they work. The core :meth:`~flask.Flask.before_request` handler, for24example, is executed in a specific order and is able to abort the request25early by returning a response. In contrast all signal handlers are26executed in undefined order and do not modify any data.2728The big advantage of signals over handlers is that you can safely
162 unmodified lines
modified:docs/testing.rst+2 added-2 removed
221 unmodified lines
222there does not seem to be a good way to do that, consider switching to223application factories (see :ref:`app-factories`).224225Note however that if you are using a test request context, the226:meth:`~flask.Flask.before_request` functions are not automatically called227same for :meth:`~flask.Flask.after_request` functions. However226:meth:`~flask.Flask.before_request` and :meth:`~flask.Flask.after_request`227functions are not called automatically. However228:meth:`~flask.Flask.teardown_request` functions are indeed executed when229the test request context leaves the ``with`` block. If you do want the230:meth:`~flask.Flask.before_request` functions to be called as well, you231need to call :meth:`~flask.Flask.preprocess_request` yourself::
124 unmodified lines