Merge pull request #1240 from defuz/docs-style-fix-2
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Docs style fixes: ``FOO`` vs `FOO` (reloaded)
authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents 2ab9144, 7e157ee · Browse files · 61 files·+396 added−396 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
61 files+396 added−396 removed
- other:+396 added−396 removed
Provenance
- Commit
6fcc2ae- Tree
1221732- Author
Markus Unterwaditzer <markus@unterwaditzer.net>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent 1
2ab9144- Parent 2
7e157ee
61 files changed+396 added−396 removed
modified:docs/deploying/cgi.rst+4 added-4 removed
22 unmodified lines23 Creating a `.cgi` file24 ----------------------25 26 First you need to create the CGI application file. Let's call it27-`yourapplication.cgi`::27+:file:`yourapplication.cgi`::28 29 #!/usr/bin/python30 from wsgiref.handlers import CGIHandler31 from yourapplication import app3 unmodified lines35 Server Setup36 ------------37 38 Usually there are two ways to configure the server. Either just copy the39-`.cgi` into a `cgi-bin` (and use `mod_rewrite` or something similar to39+``.cgi`` into a :file:`cgi-bin` (and use `mod_rewrite` or something similar to40 rewrite the URL) or let the server point to the file directly.41 42 In Apache for example you can put something like this into the config:43 1 unmodified line45 46 ScriptAlias /app /path/to/the/application.cgi47 48 On shared webhosting, though, you might not have access to your Apache config.49-In this case, a file called `.htaccess`, sitting in the public directory you want50-your app to be available, works too but the `ScriptAlias` directive won't49+In this case, a file called ``.htaccess``, sitting in the public directory you want50+your app to be available, works too but the ``ScriptAlias`` directive won't51 work in that case:52 53 .. sourcecode:: apache54 7 unmodified linesmodified:docs/deploying/fastcgi.rst+6 added-6 removed
38 unmodified lines39 40 The path has to be the exact same path you define in the server41 config.42 43-Save the `yourapplication.fcgi` file somewhere you will find it again.44-It makes sense to have that in `/var/www/yourapplication` or something43+Save the :file:`yourapplication.fcgi` file somewhere you will find it again.44+It makes sense to have that in :file:`/var/www/yourapplication` or something45 similar.46 47 Make sure to set the executable bit on that file so that the servers48 can execute it:6 unmodified lines55 ------------------56 57 The example above is good enough for a basic Apache deployment but your58 `.fcgi` file will appear in your application URL e.g.59-example.com/yourapplication.fcgi/news/. There are few ways to configure59+``example.com/yourapplication.fcgi/news/``. There are few ways to configure60 your application so that yourapplication.fcgi does not appear in the URL.61 A preferable way is to use the ScriptAlias and SetHandler configuration62 directives to route requests to the FastCGI server. The following example63 uses FastCgiServer to start 5 instances of the application which will88 unmodified lines152 "^(/.*)$" => "/yourapplication.fcgi$1"153 )154 155 Remember to enable the FastCGI, alias and rewrite modules. This configuration156-binds the application to `/yourapplication`. If you want the application to156+binds the application to ``/yourapplication``. If you want the application to157 work in the URL root you have to work around a lighttpd bug with the158 :class:`~werkzeug.contrib.fixers.LighttpdCGIRootFix` middleware.159 160 Make sure to apply it only if you are mounting the application the URL18 unmodified lines179 fastcgi_param SCRIPT_NAME $fastcgi_script_name;180 fastcgi_pass unix:/tmp/yourapplication-fcgi.sock;181 }182 183-This configuration binds the application to `/yourapplication`. If you183+This configuration binds the application to ``/yourapplication``. If you184 want to have it in the URL root it's a bit simpler because you don't185-have to figure out how to calculate `PATH_INFO` and `SCRIPT_NAME`::185+have to figure out how to calculate ``PATH_INFO`` and ``SCRIPT_NAME``::186 187 location / { try_files $uri @yourapplication; }188 location @yourapplication {189 include fastcgi_params;51 unmodified linesmodified:docs/deploying/mod_wsgi.rst+7 added-7 removed
50 unmodified lines51 52 Creating a `.wsgi` file53 -----------------------54 55-To run your application you need a `yourapplication.wsgi` file. This file55+To run your application you need a :file:`yourapplication.wsgi` file. This file56 contains the code `mod_wsgi` is executing on startup to get the application57 object. The object called `application` in that file is then used as58 application.59 4 unmodified lines64 If you don't have a factory function for application creation but a singleton65 instance you can directly import that one as `application`.66 67 Store that file somewhere that you will find it again (e.g.:68-`/var/www/yourapplication`) and make sure that `yourapplication` and all68+:file:`/var/www/yourapplication`) and make sure that `yourapplication` and all69 the libraries that are in use are on the python load path. If you don't70 want to install it system wide consider using a `virtual python`_71 instance. Keep in mind that you will have to actually install your72 application into the virtualenv as well. Alternatively there is the73-option to just patch the path in the `.wsgi` file before the import::73+option to just patch the path in the ``.wsgi`` file before the import::74 75 import sys76 sys.path.insert(0, '/path/to/the/application')77 53 unmodified lines131 **Problem:** application does not run, errorlog shows SystemExit ignored132 You have a ``app.run()`` call in your application file that is not133 guarded by an ``if __name__ == '__main__':`` condition. Either134 remove that :meth:`~flask.Flask.run` call from the file and move it135- into a separate `run.py` file or put it into such an if block.135+ into a separate :file:`run.py` file or put it into such an if block.136 137 **Problem:** application gives permission errors138 Probably caused by your application running as the wrong user. Make139 sure the folders the application needs access to have the proper30 unmodified lines170 Support for Automatic Reloading171 -------------------------------172 173 To help deployment tools you can activate support for automatic174-reloading. Whenever something changes the `.wsgi` file, `mod_wsgi` will174+reloading. Whenever something changes the ``.wsgi`` file, `mod_wsgi` will175 reload all the daemon processes for us.176 177 For that, just add the following directive to your `Directory` section:178 6 unmodified lines185 186 Virtual environments have the advantage that they never install the187 required dependencies system wide so you have a better control over what188 is used where. If you want to use a virtual environment with mod_wsgi189-you have to modify your `.wsgi` file slightly.189+you have to modify your ``.wsgi`` file slightly.190 191-Add the following lines to the top of your `.wsgi` file::191+Add the following lines to the top of your ``.wsgi`` file::192 193 activate_this = '/path/to/env/bin/activate_this.py'194 execfile(activate_this, dict(__file__=activate_this))195 2 unmodified linesmodified:docs/deploying/uwsgi.rst+2 added-2 removed
49 unmodified lines50 uwsgi_modifier1 30;51 uwsgi_pass unix:/tmp/uwsgi.sock;52 }53 54-This configuration binds the application to `/yourapplication`. If you want54+This configuration binds the application to ``/yourapplication``. If you want55 to have it in the URL root it's a bit simpler because you don't have to tell56-it the WSGI `SCRIPT_NAME` or set the uwsgi modifier to make use of it::56+it the WSGI ``SCRIPT_NAME`` or set the uwsgi modifier to make use of it::57 58 location / { try_files $uri @yourapplication; }59 location @yourapplication {60 include uwsgi_params;7 unmodified linesmodified:docs/deploying/wsgi-standalone.rst+4 added-4 removed
72 unmodified lines73 ------------74 75 If you deploy your application using one of these servers behind an HTTP proxy76 you will need to rewrite a few headers in order for the application to work.77-The two problematic values in the WSGI environment usually are `REMOTE_ADDR`78-and `HTTP_HOST`. You can configure your httpd to pass these headers, or you77+The two problematic values in the WSGI environment usually are ``REMOTE_ADDR``78+and ``HTTP_HOST``. You can configure your httpd to pass these headers, or you79 can fix them in middleware. Werkzeug ships a fixer that will solve some common80 setups, but you might want to write your own WSGI middleware for specific81 setups.82 20 unmodified lines103 }104 }105 106 If your httpd is not providing these headers, the most common setup invokes the107-host being set from `X-Forwarded-Host` and the remote address from108-`X-Forwarded-For`::107+host being set from ``X-Forwarded-Host`` and the remote address from108+``X-Forwarded-For``::109 110 from werkzeug.contrib.fixers import ProxyFix111 app.wsgi_app = ProxyFix(app.wsgi_app)112 21 unmodified linesmodified:docs/patterns/apierrors.rst+1 added-1 removed
2 unmodified lines3 4 It's very common to implement RESTful APIs on top of Flask. One of the5 first thing that developers run into is the realization that the builtin6 exceptions are not expressive enough for APIs and that the content type of7-``text/html`` they are emitting is not very useful for API consumers.7+:mimetype:`text/html` they are emitting is not very useful for API consumers.8 9 The better solution than using ``abort`` to signal errors for invalid API10 usage is to implement your own exception type and install an error handler11 for it that produces the errors in the format the user is expecting.52 unmodified linesmodified:docs/patterns/appdispatch.rst+4 added-4 removed
57 unmodified lines58 here is that each Flask application is a valid WSGI application and they59 are combined by the dispatcher middleware into a larger one that60 dispatched based on prefix.61 62-For example you could have your main application run on `/` and your63-backend interface on `/backend`::62+For example you could have your main application run on ``/`` and your63+backend interface on ``/backend``::64 65 from werkzeug.wsgi import DispatcherMiddleware66 from frontend_app import application as frontend67 from backend_app import application as backend75 unmodified lines143 Dispatch by Path144 ----------------145 146 Dispatching by a path on the URL is very similar. Instead of looking at147-the `Host` header to figure out the subdomain one simply looks at the147+the ``Host`` header to figure out the subdomain one simply looks at the148 request path up to the first slash::149 150 from threading import Lock151 from werkzeug.wsgi import pop_path_info, peek_path_info23 unmodified lines175 app = self.default_app176 return app(environ, start_response)177 178 The big difference between this and the subdomain one is that this one179-falls back to another application if the creator function returns `None`::179+falls back to another application if the creator function returns ``None``::180 181 from myapplication import create_app, default_app, get_user_for_prefix182 183 def make_app(prefix):5 unmodified linesmodified:docs/patterns/appfactories.rst+7 added-7 removed
58 unmodified lines59 60 It's preferable to create your extensions and app factories so that the61 extension object does not initially get bound to the application.62 63-Using `Flask-SQLAlchemy <http://pythonhosted.org/Flask-SQLAlchemy/>`_, 63+Using `Flask-SQLAlchemy <http://pythonhosted.org/Flask-SQLAlchemy/>`_,64 as an example, you should not do something along those lines::65- 65+66 def create_app(config_filename):67 app = Flask(__name__)68 app.config.from_pyfile(config_filename)69 1 unmodified line71 72 But, rather, in model.py (or equivalent)::73 74 db = SQLAlchemy()75- 75+76 and in your application.py (or equivalent)::77 78 def create_app(config_filename):79 app = Flask(__name__)2 unmodified lines82 from yourapplication.model import db83 db.init_app(app)84 85 Using this design pattern, no application-specific state is stored on the86-extension object, so one extension object can be used for multiple apps. 86+extension object, so one extension object can be used for multiple apps.87 For more information about the design of extensions refer to :doc:`/extensiondev`.88 89 Using Applications90 ------------------91 92 So to use such an application you then have to create the application93-first in a separate file otherwise the ``flask`` command won't be able94-to find it. Here an example `exampleapp.py` file that creates such93+first in a separate file otherwise the :command:`flask` command won't be able94+to find it. Here an example :file:`exampleapp.py` file that creates such95 an application::96 97 from yourapplication import create_app98 app = create_app('/path/to/config.cfg')99 100-It can then be used with the ``flask`` command::100+It can then be used with the :command:`flask` command::101 102 flask --app=exampleapp run103 104 Factory Improvements11 unmodified linesmodified:docs/patterns/caching.rst+1 added-1 removed
48 unmodified lines49 50 To get an item from the cache call51 :meth:`~werkzeug.contrib.cache.BaseCache.get` with a string as key name.52 If something is in the cache, it is returned. Otherwise that function53-will return `None`::53+will return ``None``::54 55 rv = cache.get('my-item')56 57 To add items to the cache, use the :meth:`~werkzeug.contrib.cache.BaseCache.set`12 unmodified linesmodified:docs/patterns/celery.rst+1 added-1 removed
11 unmodified lines12 Installing Celery13 -----------------14 15 Celery is on the Python Package Index (PyPI), so it can be installed with16-standard Python tools like ``pip`` or ``easy_install``::16+standard Python tools like :command:`pip` or :command:`easy_install`::17 18 $ pip install celery19 20 Configuring Celery72 unmodified linesmodified:docs/patterns/distribute.rst+12 added-12 removed
16 unmodified lines17 provided by one package from another package. The best known feature of18 this system is the entry point support which allows one package to19 declare an "entry point" another package can hook into to extend the20 other package.21-- **installation manager**: `easy_install`, which comes with distribute21+- **installation manager**: :command:`easy_install`, which comes with distribute22 can install other libraries for you. You can also use `pip`_ which23- sooner or later will replace `easy_install` which does more than just23+ sooner or later will replace :command:`easy_install` which does more than just24 installing packages for you.25 26 Flask itself, and all the libraries you can find on the cheeseshop27 are distributed with either distribute, the older setuptools or distutils.28 29 In this case we assume your application is called30-`yourapplication.py` and you are not using a module, but a :ref:`package30+:file:`yourapplication.py` and you are not using a module, but a :ref:`package31 <larger-applications>`. Distributing resources with standard modules is32 not supported by `distribute`_ so we will not bother with it. If you have33 not yet converted your application into a package, head over to the34 :ref:`larger-applications` pattern to see how this can be done.12 unmodified lines47 48 Standard disclaimer applies: :ref:`you better use a virtualenv49 <virtualenv>`.50 51-Your setup code always goes into a file named `setup.py` next to your51+Your setup code always goes into a file named :file:`setup.py` next to your52 application. The name of the file is only convention, but because53 everybody will look for a file with that name, you better not change it.54 55 Yes, even if you are using `distribute`, you are importing from a package56 called `setuptools`. `distribute` is fully backwards compatible with57 `setuptools`, so it also uses the same import name.58 59-A basic `setup.py` file for a Flask application looks like this::59+A basic :file:`setup.py` file for a Flask application looks like this::60 61 from setuptools import setup62 63 setup(18 unmodified lines82 )83 84 Most parameters to the `setup` function should be self explanatory,85 `include_package_data` and `zip_safe` might not be.86-`include_package_data` tells distribute to look for a `MANIFEST.in` file86+`include_package_data` tells distribute to look for a :file:`MANIFEST.in` file87 and install all the entries that match as package data. We will use this88 to distribute the static files and templates along with the Python module89 (see :ref:`distributing-resources`). The `zip_safe` flag can be used to90 force or prevent zip Archive creation. In general you probably don't want6 unmodified lines97 Distributing Resources98 ----------------------99 100 If you try to install the package you just created, you will notice that101-folders like `static` or `templates` are not installed for you. The101+folders like :file:`static` or :file:`templates` are not installed for you. The102 reason for this is that distribute does not know which files to add for103-you. What you should do, is to create a `MANIFEST.in` file next to your104-`setup.py` file. This file lists all the files that should be added to103+you. What you should do, is to create a :file:`MANIFEST.in` file next to your104+:file:`setup.py` file. This file lists all the files that should be added to105 your tarball::106 107 recursive-include yourapplication/templates *108 recursive-include yourapplication/static *109 110-Don't forget that even if you enlist them in your `MANIFEST.in` file, they110+Don't forget that even if you enlist them in your :file:`MANIFEST.in` file, they111 won't be installed for you unless you set the `include_package_data`112-parameter of the `setup` function to `True`!112+parameter of the `setup` function to ``True``!113 114 115 Declaring Dependencies116 ----------------------27 unmodified lines144 Installing / Developing145 -----------------------146 147 To install your application (ideally into a virtualenv) just run the148-`setup.py` script with the `install` parameter. It will install your148+:file:`setup.py` script with the `install` parameter. It will install your149 application into the virtualenv's site-packages folder and also download150 and install all dependencies::151 152 $ python setup.py install14 unmodified linesmodified:docs/patterns/fabric.rst+16 added-16 removed
13 unmodified lines14 15 - Fabric 1.0 has to be installed locally. This tutorial assumes the16 latest version of Fabric.17 - The application already has to be a package and requires a working18- `setup.py` file (:ref:`distribute-deployment`).18+ :file:`setup.py` file (:ref:`distribute-deployment`).19 - In the following example we are using `mod_wsgi` for the remote20 servers. You can of course use your own favourite server there, but21 for this example we chose Apache + `mod_wsgi` because it's very easy22 to setup and has a simple way to reload applications without root1 unmodified line24 25 Creating the first Fabfile26 --------------------------27 28-A fabfile is what controls what Fabric executes. It is named `fabfile.py`28+A fabfile is what controls what Fabric executes. It is named :file:`fabfile.py`29 and executed by the `fab` command. All the functions defined in that file30 will show up as `fab` subcommands. They are executed on one or more31 hosts. These hosts can be defined either in the fabfile or on the command32 line. In this case we will add them to the fabfile.38 unmodified lines71 - `run` - executes a command on a remote server72 - `local` - executes a command on the local machine73 - `put` - uploads a file to the remote server74 - `cd` - changes the directory on the serverside. This has to be used75- in combination with the `with` statement.75+ in combination with the ``with`` statement.76 77 Running Fabfiles78 ----------------79 3 unmodified lines83 84 $ fab pack deploy85 86 However this requires that our server already has the87-``/var/www/yourapplication`` folder created and88-``/var/www/yourapplication/env`` to be a virtual environment. Furthermore89-are we not creating the configuration or `.wsgi` file on the server. So87+:file:`/var/www/yourapplication` folder created and88+:file:`/var/www/yourapplication/env` to be a virtual environment. Furthermore89+are we not creating the configuration or ``.wsgi`` file on the server. So90 how do we bootstrap a new server into our infrastructure?91 92 This now depends on the number of servers we want to set up. If we just93 have one application server (which the majority of applications will5 unmodified lines99 $ fab -H newserver.example.com bootstrap100 101 To setup a new server you would roughly do these steps:102 103-1. Create the directory structure in ``/var/www``::103+1. Create the directory structure in :file:`/var/www`::104 105 $ mkdir /var/www/yourapplication106 $ cd /var/www/yourapplication107 $ virtualenv --distribute env108 109-2. Upload a new `application.wsgi` file to the server and the110- configuration file for the application (eg: `application.cfg`)109+2. Upload a new :file:`application.wsgi` file to the server and the110+ configuration file for the application (eg: :file:`application.cfg`)111 112-3. Create a new Apache config for `yourapplication` and activate it.113- Make sure to activate watching for changes of the `.wsgi` file so112+3. Create a new Apache config for ``yourapplication`` and activate it.113+ Make sure to activate watching for changes of the ``.wsgi`` file so114 that we can automatically reload the application by touching it.115 (See :ref:`mod_wsgi-deployment` for more information)116 117-So now the question is, where do the `application.wsgi` and118-`application.cfg` files come from?117+So now the question is, where do the :file:`application.wsgi` and118+:file:`application.cfg` files come from?119 120 The WSGI File121 -------------122 18 unmodified lines141 The Configuration File142 ----------------------143 144 Now as mentioned above, the application will find the correct145-configuration file by looking up the `YOURAPPLICATION_CONFIG` environment145+configuration file by looking up the ``YOURAPPLICATION_CONFIG`` environment146 variable. So we have to put the configuration in a place where the147 application will able to find it. Configuration files have the unfriendly148 quality of being different on all computers, so you do not version them149 usually.150 151 A popular approach is to store configuration files for different servers152 in a separate version control repository and check them out on all153 servers. Then symlink the file that is active for the server into the154-location where it's expected (eg: ``/var/www/yourapplication``).154+location where it's expected (eg: :file:`/var/www/yourapplication`).155 156 Either way, in our case here we only expect one or two servers and we can157 upload them ahead of time by hand.158 8 unmodified lines167 168 Fabric will now connect to all servers and run the commands as written169 down in the fabfile. First it will execute pack so that we have our170 tarball ready and then it will execute deploy and upload the source code171-to all servers and install it there. Thanks to the `setup.py` file we171+to all servers and install it there. Thanks to the :file:`setup.py` file we172 will automatically pull in the required libraries into our virtual173 environment.174 175 Next Steps21 unmodified linesmodified:docs/patterns/fileuploads.rst+4 added-4 removed
30 unmodified lines31 app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER32 33 So first we need a couple of imports. Most should be straightforward, the34 :func:`werkzeug.secure_filename` is explained a little bit later. The35-`UPLOAD_FOLDER` is where we will store the uploaded files and the36-`ALLOWED_EXTENSIONS` is the set of allowed file extensions. Then we add a35+``UPLOAD_FOLDER`` is where we will store the uploaded files and the36+``ALLOWED_EXTENSIONS`` is the set of allowed file extensions. Then we add a37 URL rule by hand to the application. Now usually we're not doing that, so38 why here? The reasons is that we want the webserver (or our development39 server) to serve these files for us and so we only need a rule to generate40 the URL to these files.1 unmodified line42 Why do we limit the extensions that are allowed? You probably don't want43 your users to be able to upload everything there if the server is directly44 sending out the data to the client. That way you can make sure that users45 are not able to upload HTML files that would cause XSS problems (see46-:ref:`xss`). Also make sure to disallow `.php` files if the server46+:ref:`xss`). Also make sure to disallow ``.php`` files if the server47 executes them, but who has PHP installed on his server, right? :)48 49 Next the functions that check if an extension is valid and that uploads50 the file and redirects the user to the URL for the uploaded file::46 unmodified lines97 98 filename = "../../../../home/username/.bashrc"99 100 Assuming the number of ``../`` is correct and you would join this with101- the `UPLOAD_FOLDER` the user might have the ability to modify a file on101+ the ``UPLOAD_FOLDER`` the user might have the ability to modify a file on102 the server's filesystem he or she should not modify. This does require some103 knowledge about how the application looks like, but trust me, hackers104 are patient :)105 85 unmodified linesmodified:docs/patterns/flashing.rst+1 added-1 removed
36 unmodified lines37 flash('You were successfully logged in')38 return redirect(url_for('index'))39 return render_template('login.html', error=error)40 41-And here the ``layout.html`` template which does the magic:41+And here the :file:`layout.html` template which does the magic:42 43 .. sourcecode:: html+jinja44 45 <!doctype html>102 unmodified linesmodified:docs/patterns/jquery.rst+6 added-6 removed
17 unmodified lines18 19 In order to use jQuery, you have to download it first and place it in the20 static folder of your application and then ensure it's loaded. Ideally21 you have a layout template that is used for all pages where you just have22-to add a script statement to the bottom of your `<body>` to load jQuery:22+to add a script statement to the bottom of your ``<body>`` to load jQuery:23 24 .. sourcecode:: html25 26 <script type=text/javascript src="{{37 unmodified lines64 </script>65 66 The ``|safe`` is necessary in Flask before 0.10 so that Jinja does not67 escape the JSON encoded string with HTML rules. Usually this would be68-necessary, but we are inside a `script` block here where different rules68+necessary, but we are inside a ``script`` block here where different rules69 apply.70 71 .. admonition:: Information for Pros72 73- In HTML the `script` tag is declared `CDATA` which means that entities73+ In HTML the ``script`` tag is declared ``CDATA`` which means that entities74 will not be parsed. Everything until ``</script>`` is handled as script.75 This also means that there must never be any ``</`` between the script76 tags. ``|tojson`` is kind enough to do the right thing here and77 escape slashes for you (``{{ "</script>"|tojson|safe }}`` is rendered as40 unmodified lines118 119 The HTML120 --------121 122-Your index.html template either has to extend a `layout.html` template with122+Your index.html template either has to extend a :file:`layout.html` template with123 jQuery loaded and the `$SCRIPT_ROOT` variable set, or do that on the top.124-Here's the HTML code needed for our little application (`index.html`).124+Here's the HTML code needed for our little application (:file:`index.html`).125 Notice that we also drop the script directly into the HTML here. It is126 usually a better idea to have that in a separate script file:127 128 .. sourcecode:: html26 unmodified lines155 3. ``element.bind('event', func)`` specifies a function that should run156 when the user clicked on the element. If that function returns157 `false`, the default behavior will not kick in (in this case, navigate158 to the `#` URL).159-4. ``$.getJSON(url, data, func)`` sends a `GET` request to `url` and will159+4. ``$.getJSON(url, data, func)`` sends a ``GET`` request to `url` and will160 send the contents of the `data` object as query parameters. Once the161 data arrived, it will call the given function with the return value as162 argument. Note that we can use the `$SCRIPT_ROOT` variable here that163 we set earlier.5 unmodified linesmodified:docs/patterns/lazyloading.rst+1 added-1 removed
31 unmodified lines32 def user(username):33 pass34 35 Then the centralized approach you would have one file with the views36-(`views.py`) but without any decorator::36+(:file:`views.py`) but without any decorator::37 38 def index():39 pass40 64 unmodified linesmodified:docs/patterns/mongokit.rst+3 added-3 removed
18 unmodified lines19 20 The default behavior of MongoKit is the declarative one that is based on21 common ideas from Django or the SQLAlchemy declarative extension.22 23-Here an example `app.py` module for your application::23+Here an example :file:`app.py` module for your application::24 25 from flask import Flask26 from mongokit import Connection, Document27 18 unmodified lines46 MongoDB is schemaless. This means you can modify the data structure from one47 insert query to the next without any problem. MongoKit is just schemaless48 too, but implements some validation to ensure data integrity.49 50-Here is an example document (put this also into `app.py`, e.g.)::50+Here is an example document (put this also into :file:`app.py`, e.g.)::51 52 def max_length(length):53 def validate(value):54 if len(value) <= length:20 unmodified lines75 76 This example shows you how to define your schema (named structure), a77 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 your79+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 separate between attributes.82 83 You can insert entries into the database like this:58 unmodified linesmodified:docs/patterns/packages.rst+11 added-11 removed
19 unmodified lines20 Simple Packages21 ---------------22 23 To convert that into a larger one, just create a new folder24-`yourapplication` inside the existing one and move everything below it.25-Then rename `yourapplication.py` to `__init__.py`. (Make sure to delete26-all `.pyc` files first, otherwise things would most likely break)24+:file:`yourapplication` inside the existing one and move everything below it.25+Then rename :file:`yourapplication.py` to :file:`__init__.py`. (Make sure to delete26+all ``.pyc`` files first, otherwise things would most likely break)27 28 You should then end up with something like that::29 30 /yourapplication9 unmodified lines40 41 But how do you run your application now? The naive ``python42 yourapplication/__init__.py`` will not work. Let's just say that Python43 does not want modules in packages to be the startup file. But that is not44-a big problem, just add a new file called `runserver.py` next to the inner45-`yourapplication` folder with the following contents::44+a big problem, just add a new file called :file:`runserver.py` next to the inner45+:file:`yourapplication` folder with the following contents::46 47 from yourapplication import app48 app.run(debug=True)49 1 unmodified line51 into multiple modules. The only thing you have to remember is the52 following quick checklist:53 54 1. the `Flask` application object creation has to be in the55- `__init__.py` file. That way each module can import it safely and the55+ :file:`__init__.py` file. That way each module can import it safely and the56 `__name__` variable will resolve to the correct package.57 2. all the view functions (the ones with a :meth:`~flask.Flask.route`58- decorator on top) have to be imported in the `__init__.py` file.58+ decorator on top) have to be imported in the :file:`__init__.py` file.59 Not the object itself, but the module it is in. Import the view module60 **after the application object is created**.61 62-Here's an example `__init__.py`::62+Here's an example :file:`__init__.py`::63 64 from flask import Flask65 app = Flask(__name__)66 67 import yourapplication.views68 69-And this is what `views.py` would look like::69+And this is what :file:`views.py` would look like::70 71 from yourapplication import app72 73 @app.route('/')18 unmodified lines92 .. admonition:: Circular Imports93 94 Every Python programmer hates them, and yet we just added some:95 circular imports (That's when two modules depend on each other. In this96- case `views.py` depends on `__init__.py`). Be advised that this is a96+ case :file:`views.py` depends on :file:`__init__.py`). Be advised that this is a97 bad idea in general but here it is actually fine. The reason for this is98- that we are not actually using the views in `__init__.py` and just98+ that we are not actually using the views in :file:`__init__.py` and just99 ensuring the module is imported and we are doing that at the bottom of100 the file.101 102 There are still some problems with that approach but if you want to use13 unmodified linesmodified:docs/patterns/sqlalchemy.rst+4 added-4 removed
31 unmodified lines32 SQLAlchemy. It allows you to define tables and models in one go, similar33 to how Django works. In addition to the following text I recommend the34 official documentation on the `declarative`_ extension.35 36-Here the example `database.py` module for your application::36+Here the example :file:`database.py` module for your application::37 38 from sqlalchemy import create_engine39 from sqlalchemy.orm import scoped_session, sessionmaker40 from sqlalchemy.ext.declarative import declarative_base28 unmodified lines69 @app.teardown_appcontext70 def shutdown_session(exception=None):71 db_session.remove()72 73-Here is an example model (put this into `models.py`, e.g.)::73+Here is an example model (put this into :file:`models.py`, e.g.)::74 75 from sqlalchemy import Column, Integer, String76 from yourapplication.database import Base77 43 unmodified lines121 flexible but a little more to type. In general it works like the122 declarative approach, so make sure to also split up your application into123 multiple modules in a package.124 125-Here is an example `database.py` module for your application::125+Here is an example :file:`database.py` module for your application::126 127 from sqlalchemy import create_engine, MetaData128 from sqlalchemy.orm import scoped_session, sessionmaker129 14 unmodified lines144 @app.teardown_appcontext145 def shutdown_session(exception=None):146 db_session.remove()147 148-Here is an example table and model (put this into `models.py`)::148+Here is an example table and model (put this into :file:`models.py`)::149 150 from sqlalchemy import Table, Column, Integer, String151 from sqlalchemy.orm import mapper152 from yourapplication.database import metadata, db_session66 unmodified linesmodified:docs/patterns/templateinheritance.rst+1 added-1 removed
12 unmodified lines13 14 Base Template15 -------------16 17-This template, which we'll call ``layout.html``, defines a simple HTML skeleton17+This template, which we'll call :file:`layout.html`, defines a simple HTML skeleton18 document that you might use for a simple two-column page. It's the job of19 "child" templates to fill the empty blocks with content:20 21 .. sourcecode:: html+jinja49 unmodified linesmodified:docs/patterns/viewdecorators.rst+9 added-9 removed
21 unmodified lines22 often forgotten, but you don't have to do that by hand, there is a23 function for that that is used like a decorator (:func:`functools.wraps`).24 25 This example assumes that the login page is called ``'login'`` and that26-the current user is stored as `g.user` and `None` if there is no-one26+the current user is stored as `g.user` and ``None`` if there is no-one27 logged in::28 29 from functools import wraps30 from flask import g, request, redirect, url_for88 unmodified lines119 As you can see, if no template name is provided it will use the endpoint120 of the URL map with dots converted to slashes + ``'.html'``. Otherwise121 the provided template name is used. When the decorated function returns,122 the dictionary returned is passed to the template rendering function. If123-`None` is returned, an empty dictionary is assumed, if something else than123+``None`` is returned, an empty dictionary is assumed, if something else than124 a dictionary is returned we return it from the function unchanged. That125 way you can still use the redirect function or return simple strings.126 127 Here is the code for that decorator::22 unmodified lines150 Endpoint Decorator151 ------------------152 153 When you want to use the werkzeug routing system for more flexibility you154-need to map the endpoint as defined in the :class:`~werkzeug.routing.Rule` 155-to a view function. This is possible with this decorator. For example:: 154+need to map the endpoint as defined in the :class:`~werkzeug.routing.Rule`155+to a view function. This is possible with this decorator. For example::156 157 from flask import Flask158 from werkzeug.routing import Rule159 160- app = Flask(__name__) 161- app.url_map.add(Rule('/', endpoint='index')) 160+ app = Flask(__name__)161+ app.url_map.add(Rule('/', endpoint='index'))162 163- @app.endpoint('index') 164- def my_index(): 165- return "Hello world" 163+ @app.endpoint('index')164+ def my_index():165+ return "Hello world"modified:docs/patterns/wtforms.rst+7 added-7 removed
59 unmodified lines60 61 Things to remember:62 63 1. create the form from the request :attr:`~flask.request.form` value if64- the data is submitted via the HTTP `POST` method and65- :attr:`~flask.request.args` if the data is submitted as `GET`.64+ the data is submitted via the HTTP ``POST`` method and65+ :attr:`~flask.request.args` if the data is submitted as ``GET``.66 2. to validate the data, call the :func:`~wtforms.form.Form.validate`67- method which will return `True` if the data validates, `False`67+ method which will return ``True`` if the data validates, ``False``68 otherwise.69 3. to access individual values from the form, access `form.<NAME>.data`.70 71 Forms in Templates4 unmodified lines76 how easy this is. WTForms does half the form generation for us already.77 To make it even nicer, we can write a macro that renders a field with78 label and a list of errors if there are any.79 80-Here's an example `_formhelpers.html` template with such a macro:80+Here's an example :file:`_formhelpers.html` template with such a macro:81 82 .. sourcecode:: html+jinja83 84 {% macro render_field(field) %}14 unmodified lines99 arguments will be inserted as HTML attributes. So for example you can100 call ``render_field(form.username, class='username')`` to add a class to101 the input element. Note that WTForms returns standard Python unicode102 strings, so we have to tell Jinja2 that this data is already HTML escaped103-with the `|safe` filter.103+with the ``|safe`` filter.104 105-Here the `register.html` template for the function we used above which106-takes advantage of the `_formhelpers.html` template:105+Here the :file:`register.html` template for the function we used above which106+takes advantage of the :file:`_formhelpers.html` template:107 108 .. sourcecode:: html+jinja109 110 {% from "_formhelpers.html" import render_field %}16 unmodified linesmodified:docs/tutorial/css.rst+1 added-1 removed
2 unmodified lines3 Step 7: Adding Style4 ====================5 6 Now that everything else works, it's time to add some style to the7-application. Just create a stylesheet called `style.css` in the `static`7+application. Just create a stylesheet called :file:`style.css` in the :file:`static`8 folder we created before:9 10 .. sourcecode:: css11 20 unmodified linesmodified:docs/tutorial/dbcon.rst+1 added-1 removed
51 unmodified lines52 every time the app context tears down. So what does this mean?53 Essentially the app context is created before the request comes in and is54 destroyed (torn down) whenever the request finishes. A teardown can55 happen because of two reasons: either everything went well (the error56-parameter will be `None`) or an exception happened in which case the error56+parameter will be ``None``) or an exception happened in which case the error57 is passed to the teardown function.58 59 Curious about what these contexts mean? Have a look at the60 :ref:`app-context` documentation to learn more.18 unmodified linesmodified:docs/tutorial/dbinit.rst+4 added-4 removed
18 unmodified lines19 requires that we provide the path to the database which can introduce20 errors. It's a good idea to add a function that initializes the database21 for you to the application.22 23-To do this we can create a function and hook it into the ``flask`` command23+To do this we can create a function and hook it into the :command:`flask` command24 that initializes the database. Let me show you the code first. Just add25-this function below the `connect_db` function in `flaskr.py`::25+this function below the `connect_db` function in :file:`flaskr.py`::26 27 def init_db():28 db = get_db()29 with app.open_resource('schema.sql', mode='r') as f:6 unmodified lines36 init_db()37 print 'Initialized the database.'38 39 The ``app.cli.command()`` decorator registers a new command with the40-``flask`` script. When the command executes Flask will automatically40+:command:`flask` script. When the command executes Flask will automatically41 create a application context for us bound to the right application.42 Within the function we can then access :attr:`flask.g` and other things as43 we would expect. When the script ends, the application context tears down44 and the database connection is released.12 unmodified lines57 On that cursor there is a method to execute a complete script. Finally we58 only have to commit the changes. SQLite 3 and other transactional59 databases will not commit unless you explicitly tell it to.60 61-Now it is possible to create a database with the ``flask`` script::61+Now it is possible to create a database with the :command:`flask` script::62 63 flask --app=flaskr initdb64 Initialized the database.65 7 unmodified linesmodified:docs/tutorial/folders.rst+2 added-2 removed
11 unmodified lines12 13 The `flaskr` folder is not a python package, but just something where we14 drop our files. We will then put our database schema as well as main module15 into this folder. It is done in the following way. The files inside16-the `static` folder are available to users of the application via `HTTP`.16+the :file:`static` folder are available to users of the application via HTTP.17 This is the place where css and javascript files go. Inside the18-`templates` folder Flask will look for `Jinja2`_ templates. The18+:file:`templates` folder Flask will look for `Jinja2`_ templates. The19 templates you create later in the tutorial will go in this directory.20 21 Continue with :ref:`tutorial-schema`.22 1 unmodified linemodified:docs/tutorial/setup.rst+10 added-10 removed
6 unmodified lines7 Let's call it flaskr.py. We will place this file inside the flaskr folder.8 We will begin by adding the imports we need and by adding the config9 section. For small applications, it is possible to drop the configuration10 directly into the module, and this is what we will be doing here. However11-a cleaner solution would be to create a separate `.ini` or `.py` file and11+a cleaner solution would be to create a separate ``.ini`` or ``.py`` file and12 load that or import the values from there.13 14-First we add the imports in `flaskr.py`::14+First we add the imports in :file:`flaskr.py`::15 16 # all the imports17 import os18 import sqlite319 from flask import Flask, request, session, g, redirect, url_for, abort, \20 render_template, flash21 22 Next we can create our actual application and initialize it with the23-config from the same file, in `flaskr.py`::23+config from the same file, in :file:`flaskr.py`::24 25 # create our little application :)26 app = Flask(__name__)27 app.config.from_object(__name__)25 unmodified lines53 For a real-work application it's recommended to use54 :ref:`instance-folders` instead.55 56 Usually, it is a good idea to load a separate, environment specific57-configuration file. Flask allows you to import multiple configurations and it 58-will use the setting defined in the last import. This enables robust 59-configuration setups. :meth:`~flask.Config.from_envvar` can help achieve this. 60- 57+configuration file. Flask allows you to import multiple configurations and it58+will use the setting defined in the last import. This enables robust59+configuration setups. :meth:`~flask.Config.from_envvar` can help achieve this.60+61 app.config.from_envvar('FLASKR_SETTINGS', silent=True)62 63-Simply define the environment variable :envvar:`FLASKR_SETTINGS` that points to 64-a config file to be loaded. The silent switch just tells Flask to not complain 63+Simply define the environment variable :envvar:`FLASKR_SETTINGS` that points to64+a config file to be loaded. The silent switch just tells Flask to not complain65 if no such environment key is set.66 67 In addition to that you can use the :meth:`~flask.Config.from_object`68 method on the config object and provide it with an import name of a23 unmodified lines92 without problems. Do this with the following command::93 94 flask --app=flaskr --debug run95 96-The ``--debug`` flag enables or disables the interactive debugger. *Never96+The :option:`--debug` flag enables or disables the interactive debugger. *Never97 leave debug mode activated in a production system*, because it will allow98 users to execute code on the server!99 100 You will see a message telling you that server has started along with13 unmodified linesmodified:docs/tutorial/templates.rst+4 added-4 removed
12 unmodified lines13 14 We are also using template inheritance which makes it possible to reuse15 the layout of the website in all pages.16 17-Put the following templates into the `templates` folder:17+Put the following templates into the :file:`templates` folder:18 19 .. _Jinja2: http://jinja.pocoo.org/docs/templates20 21 layout.html32 unmodified lines54 55 show_entries.html56 -----------------57 58-This template extends the `layout.html` template from above to display the59-messages. Note that the `for` loop iterates over the messages we passed58+This template extends the :file:`layout.html` template from above to display the59+messages. Note that the ``for`` loop iterates over the messages we passed60 in with the :func:`~flask.render_template` function. We also tell the61-form to submit to your `add_entry` function and use `POST` as `HTTP`61+form to submit to your `add_entry` function and use ``POST`` as HTTP62 method:63 64 .. sourcecode:: html+jinja65 46 unmodified linesmodified:docs/tutorial/views.rst+4 added-4 removed
14 unmodified lines15 returned from the cursor look a bit like tuples because we are using16 the :class:`sqlite3.Row` row factory.17 18 The view function will pass the entries as dicts to the19-`show_entries.html` template and return the rendered one::19+:file:`show_entries.html` template and return the rendered one::20 21 @app.route('/')22 def show_entries():23 db = get_db()4 unmodified lines28 Add New Entry29 -------------30 31 This view lets the user add new entries if they are logged in. This only32-responds to `POST` requests, the actual form is shown on the32+responds to ``POST`` requests, the actual form is shown on the33 `show_entries` page. If everything worked out well we will34 :func:`~flask.flash` an information message to the next request and35 redirect back to the `show_entries` page::36 8 unmodified lines45 flash('New entry was successfully posted')46 return redirect(url_for('show_entries'))47 48 Note that we check that the user is logged in here (the `logged_in` key is49-present in the session and `True`).49+present in the session and ``True``).50 51 .. admonition:: Security Note52 53 Be sure to use question marks when building SQL statements, as done in the6 unmodified lines60 61 These functions are used to sign the user in and out. Login checks the62 username and password against the ones from the configuration and sets the63 `logged_in` key in the session. If the user logged in successfully, that64-key is set to `True`, and the user is redirected back to the `show_entries`64+key is set to ``True``, and the user is redirected back to the `show_entries`65 page. In addition, a message is flashed that informs the user that he or66 she was logged in successfully. If an error occurred, the template is67 notified about that, and the user is asked again::68 30 unmodified linesmodified:docs/api.rst+19 added-19 removed
31 unmodified lines32 :members:33 34 .. attribute:: form35 36- A :class:`~werkzeug.datastructures.MultiDict` with the parsed form data from `POST`37- or `PUT` requests. Please keep in mind that file uploads will not36+ A :class:`~werkzeug.datastructures.MultiDict` with the parsed form data from ``POST``37+ or ``PUT`` requests. Please keep in mind that file uploads will not38 end up here, but instead in the :attr:`files` attribute.39 40 .. attribute:: args41 28 unmodified lines70 71 .. attribute:: files72 73 A :class:`~werkzeug.datastructures.MultiDict` with files uploaded as part of a74- `POST` or `PUT` request. Each file is stored as74+ ``POST`` or ``PUT`` request. Each file is stored as75 :class:`~werkzeug.datastructures.FileStorage` object. It basically behaves like a76 standard file object you know from Python, with the difference that77 it also has a :meth:`~werkzeug.datastructures.FileStorage.save` function that can78 store the file on the filesystem.35 unmodified lines114 ============= ======================================================115 116 .. attribute:: is_xhr117 118- `True` if the request was triggered via a JavaScript118+ ``True`` if the request was triggered via a JavaScript119 `XMLHttpRequest`. This only works with libraries that support the120 ``X-Requested-With`` header and set it to `XMLHttpRequest`.121 Libraries that do that are prototype, jQuery and Mochikit and122 probably some more.54 unmodified lines177 The following attributes are interesting:178 179 .. attribute:: new180 181- `True` if the session is new, `False` otherwise.181+ ``True`` if the session is new, ``False`` otherwise.182 183 .. attribute:: modified184 185- `True` if the session object detected a modification. Be advised185+ ``True`` if the session object detected a modification. Be advised186 that modifications on mutable structures are not picked up187 automatically, in that situation you have to explicitly set the188- attribute to `True` yourself. Here an example::188+ attribute to ``True`` yourself. Here an example::189 190 # this change is not picked up because a mutable object (here191 # a list) is changed.192 session['objects'].append(42)1 unmodified line194 session.modified = True195 196 .. attribute:: permanent197 198- If set to `True` the session lives for198+ If set to ``True`` the session lives for199 :attr:`~flask.Flask.permanent_session_lifetime` seconds. The200- default is 31 days. If set to `False` (which is the default) the200+ default is 31 days. If set to ``False`` (which is the default) the201 session will be deleted when the user closes the browser.202 203 204 Session Interface73 unmodified lines278 is especially useful when combined with the :ref:`faking-resources`279 pattern for testing.280 281 Additionally as of 0.10 you can use the :meth:`get` method to282- get an attribute or `None` (or the second argument) if it's not set.282+ get an attribute or ``None`` (or the second argument) if it's not set.283 These two usages are now equivalent::284 285 user = getattr(flask.g, 'user', None)286 user = flask.g.get('user', None)88 unmodified lines375 will have that method called and then the return value is serialized376 as string.377 378 The :func:`~htmlsafe_dumps` function of this json module is also available379-as filter called ``|tojson`` in Jinja2. Note that inside `script`379+as filter called ``|tojson`` in Jinja2. Note that inside ``script``380 tags no escaping must take place, so make sure to disable escaping381-with ``|safe`` if you intend to use it inside `script` tags unless381+with ``|safe`` if you intend to use it inside ``script`` tags unless382 you are using Flask 0.10 which implies that:383 384 .. sourcecode:: html+jinja385 129 unmodified lines515 .. versionadded:: 0.6516 517 .. data:: signals_available518 519- `True` if the signaling system is available. This is the case519+ ``True`` if the signaling system is available. This is the case520 when `blinker`_ is installed.521 522 .. data:: template_rendered523 179 unmodified lines703 subdomain is assumed.704 `**options` the options to be forwarded to the underlying705 :class:`~werkzeug.routing.Rule` object. A change to706 Werkzeug is handling of method options. methods is a list707- of methods this rule should be limited to (`GET`, `POST`708- etc.). By default a rule just listens for `GET` (and709- implicitly `HEAD`). Starting with Flask 0.6, `OPTIONS` is707+ of methods this rule should be limited to (``GET``, ``POST``708+ etc.). By default a rule just listens for ``GET`` (and709+ implicitly ``HEAD``). Starting with Flask 0.6, ``OPTIONS`` is710 implicitly added and handled by the standard request711 handling. They have to be specified as keyword arguments.712 =============== ==========================================================713 18 unmodified lines732 methods from there.733 734 - `provide_automatic_options`: if this attribute is set Flask will735 either force enable or disable the automatic implementation of the736- HTTP `OPTIONS` response. This can be useful when working with737- decorators that want to customize the `OPTIONS` response on a per-view736+ HTTP ``OPTIONS`` response. This can be useful when working with737+ decorators that want to customize the ``OPTIONS`` response on a per-view738 basis.739 740 - `required_methods`: if this attribute is set, Flask will always add741 these methods when registering a URL rule even if the methods were39 unmodified lines781 782 A special decorator that informs a click callback to be passed the783 script info object as first argument. This is normally not useful784 unless you implement very special commands like the run command which785- does not want the application to be loaded yet. 785+ does not want the application to be loaded yet.786 787 .. autodata:: run_command788 789 .. autodata:: shell_commandmodified:docs/blueprints.rst+4 added-4 removed
157 unmodified lines158 159 admin = Blueprint('admin', __name__, static_folder='static')160 161 By default the rightmost part of the path is where it is exposed on the162-web. Because the folder is called ``static`` here it will be available at162+web. Because the folder is called :file:`static` here it will be available at163 the location of the blueprint + ``/static``. Say the blueprint is164 registered for ``/admin`` the static folder will be at ``/admin/static``.165 166 The endpoint is named `blueprint_name.static` so you can generate URLs to17 unmodified lines184 185 So if you have a blueprint in the folder ``yourapplication/admin`` and you186 want to render the template ``'admin/index.html'`` and you have provided187 ``templates`` as a `template_folder` you will have to create a file like188-this: ``yourapplication/admin/templates/admin/index.html``.188+this: :file:`yourapplication/admin/templates/admin/index.html`.189 190 To further reiterate this: if you have a blueprint named ``admin`` and you191-want to render a template called ``index.html`` which is specific to this191+want to render a template called :file:`index.html` which is specific to this192 blueprint, the best idea is to lay out your templates like this::193 194 yourpackage/195 blueprints/2 unmodified lines198 admin/199 index.html200 __init__.py201 202-And then when you want to render the template, use ``admin/index.html`` as202+And then when you want to render the template, use :file:`admin/index.html` as203 the name to look up the template by. If you encounter problems loading204 the correct templates enable the ``EXPLAIN_TEMPLATE_LOADING`` config205 variable which will instruct Flask to print out the steps it goes through206 to locate templates on every ``render_template`` call.33 unmodified linesmodified:docs/cli.rst+13 added-13 removed
13 unmodified lines14 15 Basic Usage16 -----------17 18-After installation of Flask you will now find a ``flask`` script installed18+After installation of Flask you will now find a :command:`flask` script installed19 into your virtualenv. If you don't want to install Flask or you have a20 special use-case you can also use ``python -m flask`` to accomplish exactly21 the same.22 1 unmodified line24 your Flask application's :attr:`Flask.cli` instance as well as some25 built-in commands that are always there. Flask extensions can also26 register more commands there if they desire so.27 28-For the ``flask`` script to work, an application needs to be discovered.28+For the :command:`flask` script to work, an application needs to be discovered.29 The two most common ways are either an environment variable30-(``FLASK_APP``) or the ``--app`` / ``-a`` parameter. It should be the30+(``FLASK_APP``) or the :option:`--app` / :option:`-a` parameter. It should be the31 import path for your application or the path to a Python file. In the32 latter case Flask will attempt to setup the Python path for you33 automatically and discover the module name but that might not always work.34 35 In that imported file the name of the app needs to be called ``app`` or36 optionally be specified after a colon.37 38-Given a ``hello.py`` file with the application in it named ``app`` this is38+Given a :file:`hello.py` file with the application in it named ``app`` this is39 how it can be run.40 41 Environment variables (On Windows use ``set`` instead of ``export``)::42 18 unmodified lines61 62 Debug Flag63 ----------64 65-The ``flask`` script can be run with ``--debug`` or ``--no-debug`` to65+The :command:`flask` script can be run with :option:`--debug` or :option:`--no-debug` to66 automatically flip the debug flag of the application. This can also be67 configured by setting ``FLASK_DEBUG`` to ``1`` or ``0``.68 69 Running a Shell51 unmodified lines121 Factory Functions122 -----------------123 124 In case you are using factory functions to create your application (see125-:ref:`app-factories`) you will discover that the ``flask`` command cannot125+:ref:`app-factories`) you will discover that the :command:`flask` command cannot126 work with them directly. Flask won't be able to figure out how to127 instantiate your application properly by itself. Because of this reason128 the recommendation is to create a separate file that instantiates129 applications. This is by far not the only way to make this work. Another2 unmodified lines132 For instance if you have a factory function that creates an application133 from a filename you could make a separate file that creates such an134 application from an environment variable.135 136-This could be a file named ``autoapp.py`` with these contents::136+This could be a file named :file:`autoapp.py` with these contents::137 138 import os139 from yourapplication import create_app140 app = create_app(os.environ['YOURAPPLICATION_CONFIG'])3 unmodified lines144 145 export YOURAPPLICATION_CONFIG=/path/to/config.cfg146 export FLASK_APP=/path/to/autoapp.py147 148-From this point onwards ``flask`` will find your application.148+From this point onwards :command:`flask` will find your application.149 150 .. _custom-scripts:151 152 Custom Scripts153 --------------154 155-While the most common way is to use the ``flask`` command, you can also155+While the most common way is to use the :command:`flask` command, you can also156 make your own "driver scripts". Since Flask uses click for the scripts157 there is no reason you cannot hook these scripts into any click158 application. There is one big caveat and that is, that commands159 registered to :attr:`Flask.cli` will expect to be (indirectly at least)1 unmodified line161 necessary so that the commands know which Flask application they have to162 work with.163 164 To understand why you might want custom scripts you need to understand how165-click finds and executes the Flask application. If you use the ``flask``165+click finds and executes the Flask application. If you use the :command:`flask`166 script you specify the application to work with on the command line or167 environment variable as an import name. This is simple but it has some168 limitations. Primarily it does not work with application factory169 functions (see :ref:`app-factories`).8 unmodified lines178 We won't go into detail now about the differences but if you are curious179 you can have a look at the :ref:`script-info-object` section to learn all180 about it.181 182-To explain all of this, here is an example ``manage.py`` script that182+To explain all of this, here is an example :file:`manage.py` script that183 manages a hypothetical wiki application. We will go through the details184 afterwards::185 186 import click35 unmodified lines222 Whenever click now needs to operate on a Flask application it will223 call that function with the script info and ask for it to be created.224 4. In step 2 you could see that the config is passed to the actual225 creation function. This config comes from the :func:`script_info_option`226- decorator for the main script. It accepts a ``--config`` option and226+ decorator for the main script. It accepts a :option:`--config` option and227 then stores it in the script info so we can use it to create the228 application.229 5. All is rounded up by invoking the script.230 7 unmodified lines238 both provide custom commands to click as well as not loading your239 application unless it has to. The reason for this is added flexibility.240 241 This way an application can provide custom commands, but even in the242-absence of an application the ``flask`` script is still operational on a242+absence of an application the :command:`flask` script is still operational on a243 basic level. In addition to that it means that the individual commands244 have the option to avoid creating an instance of the Flask application245 unless required. This is very useful as it allows the server commands for246 instance to load the application on a first request instead of13 unmodified linesmodified:docs/config.rst+10 added-10 removed
54 unmodified lines55 ``DEBUG`` enable/disable debug mode56 ``TESTING`` enable/disable testing mode57 ``PROPAGATE_EXCEPTIONS`` explicitly enable or disable the58 propagation of exceptions. If not set or59- explicitly set to `None` this is60- implicitly true if either `TESTING` or61- `DEBUG` is true.59+ explicitly set to ``None`` this is60+ implicitly true if either ``TESTING`` or61+ ``DEBUG`` is true.62 ``PRESERVE_CONTEXT_ON_EXCEPTION`` By default if the application is in63 debug mode the request context is not64 popped on exceptions to enable debuggers65 to introspect the data. This can be13 unmodified lines79 for all of ``APPLICATION_ROOT`` or if80 that is not set for ``'/'``.81 ``SESSION_COOKIE_HTTPONLY`` controls if the cookie should be set82 with the httponly flag. Defaults to83- `True`.83+ ``True``.84 ``SESSION_COOKIE_SECURE`` controls if the cookie should be set85 with the secure flag. Defaults to86- `False`.86+ ``False``.87 ``PERMANENT_SESSION_LIFETIME`` the lifetime of a permanent session as88 :class:`datetime.timedelta` object.89 Starting with Flask 0.8 this can also be90 an integer representing seconds.91 ``SESSION_REFRESH_EACH_REQUEST`` this flag controls how permanent92- sessions are refreshed. If set to `True`92+ sessions are refreshed. If set to ``True``93 (which is the default) then the cookie94 is refreshed each request which95 automatically bumps the lifetime. If96- set to `False` a `set-cookie` header is96+ set to ``False`` a `set-cookie` header is97 only sent if the session is modified.98 Non permanent sessions are not affected99 by this.100 ``USE_X_SENDFILE`` enable/disable x-sendfile25 unmodified lines126 ``MAX_CONTENT_LENGTH`` If set to a value in bytes, Flask will127 reject incoming requests with a128 content length greater than this by129 returning a 413 status code.130-``SEND_FILE_MAX_AGE_DEFAULT``: Default cache control max age to use with130+``SEND_FILE_MAX_AGE_DEFAULT`` Default cache control max age to use with131 :meth:`~flask.Flask.send_static_file` (the132 default static file handler) and133 :func:`~flask.send_file`, in134 seconds. Override this value on a per-file124 unmodified lines259 app.config.from_envvar('YOURAPPLICATION_SETTINGS')260 261 This first loads the configuration from the262 `yourapplication.default_settings` module and then overrides the values263-with the contents of the file the :envvar:`YOURAPPLICATION_SETTINGS`263+with the contents of the file the :envvar:``YOURAPPLICATION_SETTINGS``264 environment variable points to. This environment variable can be set on265 Linux or OS X with the export command in the shell before starting the266 server::267 54 unmodified lines322 app = Flask(__name__)323 app.config.from_object('yourapplication.default_settings')324 app.config.from_envvar('YOURAPPLICATION_SETTINGS')325 326-Then you just have to add a separate `config.py` file and export326+Then you just have to add a separate :file:`config.py` file and export327 ``YOURAPPLICATION_SETTINGS=/path/to/config.py`` and you are done. However328 there are alternative ways as well. For example you could use imports or329 subclassing.330 132 unmodified linesmodified:docs/extensiondev.rst+6 added-6 removed
25 unmodified lines26 The name of the actual extension (the human readable name) however would27 be something like "Flask-SimpleXML". Make sure to include the name28 "Flask" somewhere in that name and that you check the capitalization.29 This is how users can then register dependencies to your extension in30-their `setup.py` files.30+their :file:`setup.py` files.31 32 Flask sets up a redirect package called :data:`flask.ext` where users33 should import the extensions from. If you for instance have a package34 called ``flask_something`` users would import it as6 unmodified lines41 :ref:`app-factories` pattern to create their application as needed to aid42 unittests and to support multiple configurations. Because of that it is43 crucial that your application supports that kind of behavior.44 45-Most importantly the extension must be shipped with a `setup.py` file and45+Most importantly the extension must be shipped with a :file:`setup.py` file and46 registered on PyPI. Also the development checkout link should work so47 that people can easily install the development version into their48 virtualenv without having to download the library by hand.49 19 unmodified lines69 70 setup.py71 ````````72 73-The next file that is absolutely required is the `setup.py` file which is73+The next file that is absolutely required is the :file:`setup.py` file which is74 used to install your Flask extension. The following contents are75 something you can work with::76 77 """180 unmodified lines258 with app.app_context():259 cur = db.connection.cursor()260 cur.execute(...)261 262-At the end of the `with` block the teardown handles will be executed262+At the end of the ``with`` block the teardown handles will be executed263 automatically.264 265 Additionally, the ``init_app`` method is used to support the factory pattern266 for creating apps::98 unmodified lines365 2. It must ship a testing suite that can either be invoked with ``make test``366 or ``python setup.py test``. For test suites invoked with ``make367 test`` the extension has to ensure that all dependencies for the test368 are installed automatically. If tests are invoked with ``python setup.py369- test``, test dependencies can be specified in the `setup.py` file. The369+ test``, test dependencies can be specified in the :file:`setup.py` file. The370 test suite also has to be part of the distribution.371 3. APIs of approved extensions will be checked for the following372 characteristics:373 5 unmodified lines379 4. The license must be BSD/MIT/WTFPL licensed.380 5. The naming scheme for official extensions is *Flask-ExtensionName* or381 *ExtensionName-Flask*.382 6. Approved extensions must define all their dependencies in the383- `setup.py` file unless a dependency cannot be met because it is not383+ :file:`setup.py` file unless a dependency cannot be met because it is not384 available on PyPI.385 7. The extension must have documentation that uses one of the two Flask386 themes for Sphinx documentation.387 8. The setup.py description (and thus the PyPI description) has to33 unmodified linesmodified:docs/extensions.rst+2 added-2 removed
6 unmodified lines7 Finding Extensions8 ------------------9 10 Flask extensions are listed on the `Flask Extension Registry`_ and can be11-downloaded with ``easy_install`` or ``pip``. If you add a Flask extension12-as dependency to your ``requirements.rst`` or ``setup.py`` file they are11+downloaded with :command:`easy_install` or :command:`pip`. If you add a Flask extension12+as dependency to your :file:`requirements.txt` or :file:`setup.py` file they are13 usually installed with a simple command or when your application installs.14 15 Using Extensions16 ----------------32 unmodified linesmodified:docs/foreword.rst+1 added-1 removed
28 unmodified lines29 30 Flask has many configuration values, with sensible defaults, and a few31 conventions when getting started. By convention templates and static files are32 stored in subdirectories within the application's Python source tree, with the33-names `templates` and `static` respectively. While this can be changed you33+names :file:`templates` and :file:`static` respectively. While this can be changed you34 usually don't have to, especially when getting started.35 36 Growing with Flask37 ------------------20 unmodified linesmodified:docs/htmlfaq.rst+1 added-1 removed
14 unmodified lines15 However, barely any websites on the Internet are actual XHTML (which is16 HTML processed using XML rules). There are a couple of major reasons17 why this is the case. One of them is Internet Explorer's lack of proper18 XHTML support. The XHTML spec states that XHTML must be served with the MIME19-type `application/xhtml+xml`, but Internet Explorer refuses to read files19+type :mimetype:`application/xhtml+xml`, but Internet Explorer refuses to read files20 with that MIME type.21 While it is relatively easy to configure Web servers to serve XHTML properly,22 few people do. This is likely because properly using XHTML can be quite23 painful.184 unmodified linesmodified:docs/installation.rst+11 added-11 removed
52 unmodified lines53 in your package manager. If you use Ubuntu, try::54 55 $ sudo apt-get install python-virtualenv56 57-If you are on Windows and don't have the `easy_install` command, you must57+If you are on Windows and don't have the :command:`easy_install` command, you must58 install it first. Check the :ref:`windows-easy-install` section for more59 information about how to do that. Once you have it installed, run the same60-commands as above, but without the `sudo` prefix.60+commands as above, but without the :command:`sudo` prefix.61 62 Once you have virtualenv installed, just fire up a shell and create63-your own environment. I usually create a project folder and a `venv`63+your own environment. I usually create a project folder and a :file:`venv`64 folder within::65 66 $ mkdir myproject67 $ cd myproject30 unmodified lines98 System-Wide Installation99 ------------------------100 101 This is possible as well, though I do not recommend it. Just run102-`pip` with root privileges::102+:command:`pip` with root privileges::103 104 $ sudo pip install Flask105 106 (On Windows systems, run it in a command-prompt window with administrator107-privileges, and leave out `sudo`.)107+privileges, and leave out :command:`sudo`.)108 109 110 Living on the Edge111 ------------------112 113 If you want to work with the latest version of Flask, there are two ways: you114-can either let `pip` pull in the development version, or you can tell114+can either let :command:`pip` pull in the development version, or you can tell115 it to operate on a git checkout. Either way, virtualenv is recommended.116 117 Get the git checkout in a new virtualenv and run in development mode::118 37 unmodified lines156 you can upgrade them by running::157 158 > pip install --upgrade pip setuptools159 160-Most often, once you pull up a command prompt you want to be able to type ``pip``161-and ``python`` which will run those things, but this might not automatically happen160+Most often, once you pull up a command prompt you want to be able to type :command:`pip`161+and :command:`python` which will run those things, but this might not automatically happen162 on Windows, because it doesn't know where those executables are (give either a try!).163 164 To fix this, you should be able to navigate to your Python install directory165-(e.g ``C:\Python27``), then go to ``Tools``, then ``Scripts``; then find the166-``win_add2path.py`` file and run that. Open a **new** Command Prompt and167-check that you can now just type ``python`` to bring up the interpreter.165+(e.g :file:`C:\Python27`), then go to :file:`Tools`, then :file:`Scripts`; then find the166+:file:`win_add2path.py` file and run that. Open a **new** Command Prompt and167+check that you can now just type :command:`python` to bring up the interpreter.168 169 Finally, to install `virtualenv`_, you can simply run::170 171 > pip install virtualenv5 unmodified linesmodified:docs/quickstart.rst+32 added-32 removed
18 unmodified lines19 @app.route('/')20 def hello_world():21 return 'Hello World!'22 23-Just save it as `hello.py` (or something similar) and run it with your Python24-interpreter. Make sure to not call your application `flask.py` because this23+Just save it as :file:`hello.py` (or something similar) and run it with your Python24+interpreter. Make sure to not call your application :file:`flask.py` because this25 would conflict with Flask itself.26 27-To run the application you can either use the ``flask`` command or28-python's ``-m`` switch with Flask::27+To run the application you can either use the :command:`flask` command or28+python's :option:`-m` switch with Flask::29 30 $ flask -a hello run31 * Running on http://127.0.0.1:5000/32 45 unmodified lines78 79 What to do if the Server does not Start80 ---------------------------------------81 82-In case the ``python -m flask`` fails or ``flask`` does not exist,82+In case the ``python -m flask`` fails or :command:`flask` does not exist,83 there are multiple reasons this might be the case. First of all you need84 to look at the error message.85 86 Old Version of Flask87 ````````````````````88 89 Versions of Flask older than 1.0 use to have different ways to start the90-application. In short, the ``flask`` command did not exist, and90+application. In short, the :command:`flask` command did not exist, and91 neither did ``python -m flask``. In that case you have two options:92 either upgrade to newer Flask versions or have a look at the :ref:`server`93 docs to see the alternative method for running a server.94 95 Python older 2.796 ````````````````97 98 In case you have a version of Python older than 2.7 ``python -m flask``99-does not work. You can either use ``flask`` or ``python -m99+does not work. You can either use :command:`flask` or ``python -m100 flask.cli`` as an alternative. This is because Python before 2.7 does no101 permit packages to act as executable modules. For more information see102 :ref:`cli`.103 104 Invalid Import Name105 ```````````````````106 107-The ``-a`` argument to ``flask`` is the name of the module to import. In107+The :option:`-a` argument to :command:`flask` is the name of the module to import. In108 case that module is incorrectly named you will get an import error upon109 start (or if debug is enabled when you navigate to the application). It110 will tell you what it tried to import and why it failed.111 4 unmodified lines116 117 Debug Mode118 ----------119 120-The ``flask`` script is nice to start a local development server, but120+The :command:`flask` script is nice to start a local development server, but121 you would have to restart it manually after each change to your code.122 That is not very nice and Flask can do better. If you enable debug123 support the server will reload itself on code changes, and it will also124 provide you with a helpful debugger if things go wrong.125 126 There are different ways to enable the debug mode. The most obvious one127-is the ``--debug`` parameter to the ``flask`` command::127+is the :option:`--debug` parameter to the :command:`flask` command::128 129 flask --debug -a hello run130 131 This does the following things:159 unmodified lines291 HTTP Methods292 ````````````293 294 HTTP (the protocol web applications are speaking) knows different methods for295-accessing URLs. By default, a route only answers to `GET` requests, but that295+accessing URLs. By default, a route only answers to ``GET`` requests, but that296 can be changed by providing the `methods` argument to the297 :meth:`~flask.Flask.route` decorator. Here are some examples::298 299 from flask import request4 unmodified lines304 do_the_login()305 else:306 show_the_login_form()307 308-If `GET` is present, `HEAD` will be added automatically for you. You309-don't have to deal with that. It will also make sure that `HEAD` requests308+If ``GET`` is present, ``HEAD`` will be added automatically for you. You309+don't have to deal with that. It will also make sure that ``HEAD`` requests310 are handled as the `HTTP RFC`_ (the document describing the HTTP311 protocol) demands, so you can completely ignore that part of the HTTP312-specification. Likewise, as of Flask 0.6, `OPTIONS` is implemented for you312+specification. Likewise, as of Flask 0.6, ``OPTIONS`` is implemented for you313 automatically as well.314 315 You have no idea what an HTTP method is? Worry not, here is a quick316 introduction to HTTP methods and why they matter:1 unmodified line318 The HTTP method (also often called "the verb") tells the server what the319 clients wants to *do* with the requested page. The following methods are320 very common:321 322-`GET`322+``GET``323 The browser tells the server to just *get* the information stored on324 that page and send it. This is probably the most common method.325 326-`HEAD`326+``HEAD``327 The browser tells the server to get the information, but it is only328 interested in the *headers*, not the content of the page. An329- application is supposed to handle that as if a `GET` request was329+ application is supposed to handle that as if a ``GET`` request was330 received but to not deliver the actual content. In Flask you don't331 have to deal with that at all, the underlying Werkzeug library handles332 that for you.333 334-`POST`334+``POST``335 The browser tells the server that it wants to *post* some new336 information to that URL and that the server must ensure the data is337 stored and only stored once. This is how HTML forms usually338 transmit data to the server.339 340-`PUT`341- Similar to `POST` but the server might trigger the store procedure340+``PUT``341+ Similar to ``POST`` but the server might trigger the store procedure342 multiple times by overwriting the old values more than once. Now you343 might be asking why this is useful, but there are some good reasons344 to do it this way. Consider that the connection is lost during345 transmission: in this situation a system between the browser and the346 server might receive the request safely a second time without breaking347- things. With `POST` that would not be possible because it must only347+ things. With ``POST`` that would not be possible because it must only348 be triggered once.349 350-`DELETE`350+``DELETE``351 Remove the information at the given location.352 353-`OPTIONS`353+``OPTIONS``354 Provides a quick way for a client to figure out which methods are355 supported by this URL. Starting with Flask 0.6, this is implemented356 for you automatically.357 358 Now the interesting part is that in HTML4 and XHTML1, the only methods a359-form can submit to the server are `GET` and `POST`. But with JavaScript359+form can submit to the server are ``GET`` and ``POST``. But with JavaScript360 and future HTML standards you can use the other methods as well. Furthermore361 HTTP has become quite popular lately and browsers are no longer the only362 clients that are using HTTP. For instance, many revision control systems363 use it.5 unmodified lines369 370 Dynamic web applications also need static files. That's usually where371 the CSS and JavaScript files are coming from. Ideally your web server is372 configured to serve them for you, but during development Flask can do that373-as well. Just create a folder called `static` in your package or next to374-your module and it will be available at `/static` on the application.373+as well. Just create a folder called :file:`static` in your package or next to374+your module and it will be available at ``/static`` on the application.375 376 To generate URLs for static files, use the special ``'static'`` endpoint name::377 378 url_for('static', filename='style.css')379 380-The file has to be stored on the filesystem as ``static/style.css``.380+The file has to be stored on the filesystem as :file:`static/style.css`.381 382 Rendering Templates383 -------------------384 13 unmodified lines398 @app.route('/hello/<name>')399 def hello(name=None):400 return render_template('hello.html', name=name)401 402-Flask will look for templates in the `templates` folder. So if your402+Flask will look for templates in the :file:`templates` folder. So if your403 application is a module, this folder is next to that module, if it's a404 package it's actually inside your package:405 406 **Case 1**: a module::102 unmodified lines509 will notice that code which depends on a request object will suddenly break510 because there is no request object. The solution is creating a request511 object yourself and binding it to the context. The easiest solution for512 unit testing is to use the :meth:`~flask.Flask.test_request_context`513-context manager. In combination with the `with` statement it will bind a513+context manager. In combination with the ``with`` statement it will bind a514 test request so that you can interact with it. Here is an example::515 516 from flask import request517 22 unmodified lines540 from flask import request541 542 The current request method is available by using the543 :attr:`~flask.request.method` attribute. To access form data (data544-transmitted in a `POST` or `PUT` request) you can use the544+transmitted in a ``POST`` or ``PUT`` request) you can use the545 :attr:`~flask.request.form` attribute. Here is a full example of the two546 attributes mentioned above::547 548 @app.route('/login', methods=['POST', 'GET'])20 unmodified lines569 570 searchword = request.args.get('key', '')571 572 We recommend accessing URL parameters with `get` or by catching the573-`KeyError` because users might change the URL and presenting them a 400573+:exc:`KeyError` because users might change the URL and presenting them a 400574 bad request page in that case is not user friendly.575 576 For a full list of methods and attributes of the request object, head over577 to the :class:`~flask.request` documentation.129 unmodified lines707 708 The return value from a view function is automatically converted into a709 response object for you. If the return value is a string it's converted710 into a response object with the string as response body, a ``200 OK``711-status code and a ``text/html`` mimetype. The logic that Flask applies to711+status code and a :mimetype:`text/html` mimetype. The logic that Flask applies to712 converting return values into response objects is as follows:713 714 1. If a response object of the correct type is returned it's directly715 returned from the view.178 unmodified linesmodified:docs/reqcontext.rst+3 added-3 removed
35 unmodified lines36 us a :class:`~flask.ctx.RequestContext`:37 38 >>> ctx = app.test_request_context('/?next=http://example.com/')39 40-This context can be used in two ways. Either with the `with` statement40+This context can be used in two ways. Either with the ``with`` statement41 or by calling the :meth:`~flask.ctx.RequestContext.push` and42 :meth:`~flask.ctx.RequestContext.pop` methods:43 44 >>> ctx.push()29 unmodified lines74 return response(environ, start_response)75 76 The method :meth:`~Flask.request_context` returns a new77 :class:`~flask.ctx.RequestContext` object and uses it in combination with78-the `with` statement to bind the context. Everything that is called from79-the same thread from this point onwards until the end of the `with`78+the ``with`` statement to bind the context. Everything that is called from79+the same thread from this point onwards until the end of the ``with``80 statement will have access to the request globals (:data:`flask.request`81 and others).82 83 The request context internally works like a stack: The topmost level on140 unmodified linesmodified:docs/security.rst+6 added-6 removed
23 unmodified lines24 25 - generating HTML without the help of Jinja226 - calling :class:`~flask.Markup` on data submitted by users27 - sending out HTML from uploaded files, never do that, use the28- `Content-Disposition: attachment` header to prevent that problem.28+ ``Content-Disposition: attachment`` header to prevent that problem.29 - sending out textfiles from uploaded files. Some browsers are using30 content-type guessing based on the first few bytes so users could31 trick a browser to execute HTML.32 36 unmodified lines69 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 an73+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 they just has to trick some users to load that page and77 their profiles will end up being deleted.78 50 unmodified lines129 "email": "admin@localhost"}130 ]131 132 And it is doing that of course only as long as you are logged in and only133-for you. And it is doing that for all `GET` requests to a certain URL,133+for you. And it is doing that for all ``GET`` requests to a certain URL,134 say the URL for that request is135 ``http://example.com/api/get_friends.json``.136 137 So now what happens if a clever hacker is embedding this to his website22 unmodified lines160 161 If you know a bit of JavaScript internals you might know that it's162 possible to patch constructors and register callbacks for setters. An163 attacker can use this (like above) to get all the data you exported in164-your JSON file. The browser will totally ignore the ``application/json``165-mimetype if ``text/javascript`` is defined as content type in the script164+your JSON file. The browser will totally ignore the :mimetype:`application/json`165+mimetype if :mimetype:`text/javascript` is defined as content type in the script166 tag and evaluate that as JavaScript. Because top-level array elements are167 allowed (albeit useless) and we hooked in our own constructor, after that168 page loaded the data from the JSON response is in the `captured` array.169 6 unmodified linesmodified:docs/server.rst+5 added-5 removed
4 unmodified lines5 6 .. currentmodule:: flask7 8 Starting with Flask 1.0 there are multiple built-in ways to run a9-development server. The best one is the ``flask`` command line utility9+development server. The best one is the :command:`flask` command line utility10 but you can also continue using the :meth:`Flask.run` method.11 12 Command Line13 ------------14 15-The ``flask`` command line script (:ref:`cli`) is strongly recommende for15+The :command:`flask` command line script (:ref:`cli`) is strongly recommende for16 development because it provides a superior reload experience due to how it17 loads the application. The basic usage is like this::18 19 $ flask -a my_application --debug run20 21-This will enable the debugger, the reloader and then start the server on 21+This will enable the debugger, the reloader and then start the server on22 *http://localhost:5000/*.23 24 The individual features of the server can be controlled by passing more25 arguments to the ``run`` option. For instance the reloader can be5 unmodified lines31 -------32 33 The alternative way to start the application is through the34 :meth:`Flask.run` method. This will immediately launch a local server35-exactly the same way the ``flask`` script does.35+exactly the same way the :command:`flask` script does.36 37 Example::38 39 if __name__ == '__main__':40 app.run()41 42 This works well for the common case but it does not work well for43-development which is why from Flask 1.0 onwards the ``flask`` method is43+development which is why from Flask 1.0 onwards the :command:`flask` method is44 recommended. The reason for this is that due to how the reload mechanism45 works there are some bizarre side-effects (like executing certain code46 twice, sometimes crashing without message or dying when a syntax or47 import error happens).3 unmodified linesmodified:docs/shell.rst+1 added-1 removed
43 unmodified lines44 us a :class:`~flask.ctx.RequestContext`:45 46 >>> ctx = app.test_request_context()47 48-Normally you would use the `with` statement to make this request object48+Normally you would use the ``with`` statement to make this request object49 active, but in the shell it's easier to use the50 :meth:`~flask.ctx.RequestContext.push` and51 :meth:`~flask.ctx.RequestContext.pop` methods by hand:52 51 unmodified linesmodified:docs/signals.rst+2 added-2 removed
75 unmodified lines76 Make sure to subscribe with an extra ``**extra`` argument so that your77 calls don't fail if Flask introduces new arguments to the signals.78 79 All the template rendering in the code issued by the application `app`80-in the body of the `with` block will now be recorded in the `templates`80+in the body of the ``with`` block will now be recorded in the `templates`81 variable. Whenever a template is rendered, the template object as well as82 context are appended to it.83 84 Additionally there is a convenient helper method62 unmodified lines147 def save(self):148 model_saved.send(self)149 150 Try to always pick a good sender. If you have a class that is emitting a151-signal, pass `self` as sender. If you are emitting a signal from a random151+signal, pass ``self`` as sender. If you are emitting a signal from a random152 function, you can pass ``current_app._get_current_object()`` as sender.153 154 .. admonition:: Passing Proxies as Senders155 197 unmodified linesmodified:docs/styleguide.rst+1 added-1 removed
106 unmodified lines107 Comparisons:108 - against arbitrary types: ``==`` and ``!=``109 - against singletons with ``is`` and ``is not`` (eg: ``foo is not110 None``)111- - never compare something with `True` or `False` (for example never111+ - never compare something with ``True`` or ``False`` (for example never112 do ``foo == False``, do ``not foo`` instead)113 114 Negated containment checks:115 use ``foo not in bar`` instead of ``not foo in bar``85 unmodified linesmodified:docs/templating.rst+2 added-2 removed
103 unmodified lines104 This function converts the given object into JSON representation. This105 is for example very helpful if you try to generate JavaScript on the106 fly.107 108- Note that inside `script` tags no escaping must take place, so make108+ Note that inside ``script`` tags no escaping must take place, so make109 sure to disable escaping with ``|safe`` before Flask 0.10 if you intend110- to use it inside `script` tags:110+ to use it inside ``script`` tags:111 112 .. sourcecode:: html+jinja113 114 <script type=text/javascript>108 unmodified linesmodified:docs/testing.rst+6 added-6 removed
28 unmodified lines29 The Testing Skeleton30 --------------------31 32 In order to test the application, we add a second module33-(`flaskr_tests.py`) and create a unittest skeleton there::33+(:file:`flaskr_tests.py`) and create a unittest skeleton there::34 35 import os36 import flaskr37 import unittest73 unmodified lines111 112 Notice that our test functions begin with the word `test`; this allows113 :mod:`unittest` to automatically identify the method as a test to run.114 115-By using `self.app.get` we can send an HTTP `GET` request to the application with115+By using `self.app.get` we can send an HTTP ``GET`` request to the application with116 the given path. The return value will be a :class:`~flask.Flask.response_class` object.117 We can now use the :attr:`~werkzeug.wrappers.BaseResponse.data` attribute to inspect118 the return value (as string) from the application. In this case, we ensure that119 ``'No entries here so far'`` is part of the output.81 unmodified lines201 --------------------202 203 Besides using the test client as shown above, there is also the204 :meth:`~flask.Flask.test_request_context` method that can be used205-in combination with the `with` statement to activate a request context205+in combination with the ``with`` statement to activate a request context206 temporarily. With this you can access the :class:`~flask.request`,207 :class:`~flask.g` and :class:`~flask.session` objects like in view208 functions. Here is a full example that demonstrates this approach::209 13 unmodified lines223 Note however that if you are using a test request context, the224 :meth:`~flask.Flask.before_request` functions are not automatically called225 same for :meth:`~flask.Flask.after_request` functions. However226 :meth:`~flask.Flask.teardown_request` functions are indeed executed when227-the test request context leaves the `with` block. If you do want the227+the test request context leaves the ``with`` block. If you do want the228 :meth:`~flask.Flask.before_request` functions to be called as well, you229 need to call :meth:`~flask.Flask.preprocess_request` yourself::230 231 app = flask.Flask(__name__)75 unmodified lines307 308 Sometimes it is helpful to trigger a regular request but still keep the309 context around for a little longer so that additional introspection can310 happen. With Flask 0.4 this is possible by using the311-:meth:`~flask.Flask.test_client` with a `with` block::311+:meth:`~flask.Flask.test_client` with a ``with`` block::312 313 app = flask.Flask(__name__)314 315 with app.test_client() as c:316 rv = c.get('/?tequila=42')317 assert request.args['tequila'] == '42'318 319 If you were to use just the :meth:`~flask.Flask.test_client` without320-the `with` block, the `assert` would fail with an error because `request`320+the ``with`` block, the ``assert`` would fail with an error because `request`321 is no longer available (because you are trying to use it outside of the actual request).322 323 324 Accessing and Modifying Sessions29 unmodified linesmodified:docs/upgrading.rst+9 added-9 removed
12 unmodified lines13 This section of the documentation enumerates all the changes in Flask from14 release to release and how you can change your code to have a painless15 updating experience.16 17-If you want to use the `easy_install` command to upgrade your Flask18-installation, make sure to pass it the ``-U`` parameter::17+If you want to use the :command:`easy_install` command to upgrade your Flask18+installation, make sure to pass it the :option:`-U` parameter::19 20 $ easy_install -U Flask21 22 .. _upgrading-to-10:68 unmodified lines91 :exc:`~werkzeug.exceptions.BadRequest` exception instead of letting the92 default :exc:`ValueError` bubble up. This has the advantage that you no93 longer have to handle that error to avoid an internal server error showing94 up for the user. If you were catching this down explicitly in the past95-as `ValueError` you will need to change this.95+as :exc:`ValueError` you will need to change this.96 97 Due to a bug in the test client Flask 0.7 did not trigger teardown98 handlers when the test client was used in a with statement. This was99 since fixed but might require some changes in your test suites if you35 unmodified lines135 136 patch -p1 < patchfile.diff137 138 5. If you were using per-module template folders you need to move some139- templates around. Previously if you had a folder named ``templates``139+ templates around. Previously if you had a folder named :file:`templates`140 next to a blueprint named ``admin`` the implicit template path141- automatically was ``admin/index.html`` for a template file called142- ``templates/index.html``. This no longer is the case. Now you need143- to name the template ``templates/admin/index.html``. The tool will141+ automatically was :file:`admin/index.html` for a template file called142+ :file:`templates/index.html`. This no longer is the case. Now you need143+ to name the template :file:`templates/admin/index.html`. The tool will144 not detect this so you will have to do that on your own.145 146 Please note that deprecation warnings are disabled by default starting147 with Python 2.7. In order to see the deprecation warnings that might be122 unmodified lines270 some unnecessary leading dots in your code if you're not using271 modules.272 - Blueprints do not automatically provide static folders. They will273 also no longer automatically export templates from a folder called274- `templates` next to their location however but it can be enabled from274+ :file:`templates` next to their location however but it can be enabled from275 the constructor. Same with static files: if you want to continue276 serving static files you need to tell the constructor explicitly the277 path to the static folder (which can be relative to the blueprint's278 module path).279 - Rendering templates was simplified. Now the blueprints can provide280 template folders which are added to a general template searchpath.281 This means that you need to add another subfolder with the blueprint's282- name into that folder if you want ``blueprintname/template.html`` as282+ name into that folder if you want :file:`blueprintname/template.html` as283 the template name.284 285 If you continue to use the `Module` object which is deprecated, Flask will286 restore the previous behavior as good as possible. However we strongly96 unmodified linesmodified:docs/views.rst+2 added-2 removed
44 unmodified lines45 :meth:`~flask.views.View.as_view` class method. The string you pass to46 that function is the name of the endpoint that view will then have. But47 this by itself is not helpful, so let's refactor the code a bit::48 49- 49+50 from flask.views import View51 52 class ListView(View):53 16 unmodified lines70 return User.query.all()71 72 This of course is not that helpful for such a small example, but it's good73 enough to explain the basic principle. When you have a class-based view74-the question comes up what `self` points to. The way this works is that74+the question comes up what ``self`` points to. The way this works is that75 whenever the request is dispatched a new instance of the class is created76 and the :meth:`~flask.views.View.dispatch_request` method is called with77 the parameters from the URL rule. The class itself is instantiated with78 the parameters passed to the :meth:`~flask.views.View.as_view` function.159 unmodified linesmodified:examples/flaskr/README+1 added-1 removed
21 unmodified lines22 flask --app=flaskr run23 24 the application will greet you on25 http://localhost:5000/26- 26+27 ~ Is it tested?28 29 You betcha. Run the `test_flaskr.py` file to see30 the tests pass.modified:examples/minitwit/README+1 added-1 removed
22 unmodified lines23 flask --app=minitwit run24 25 the application will greet you on26 http://localhost:5000/27- 27+28 ~ Is it tested?29 30 You betcha. Run the `test_minitwit.py` file to31 see the tests pass.modified:flask/app.py+53 added-53 removed
69 unmodified lines70 71 The name of the package is used to resolve resources from inside the72 package or the folder the module is contained in depending on if the73 package parameter resolves to an actual python package (a folder with74- an `__init__.py` file inside) or a standard module (just a `.py` file).74+ an :file:`__init__.py` file inside) or a standard module (just a ``.py`` file).75 76 For more information about resource loading, see :func:`open_resource`.77 78 Usually you create a :class:`Flask` instance in your main module or79- in the `__init__.py` file of your package like this::79+ in the :file:`__init__.py` file of your package like this::80 81 from flask import Flask82 app = Flask(__name__)83 8 unmodified lines92 module, `__name__` is always the correct value. If you however are93 using a package, it's usually recommended to hardcode the name of94 your package there.95 96- For example if your application is defined in `yourapplication/app.py`96+ For example if your application is defined in :file:`yourapplication/app.py`97 you should create it with one of the two versions below::98 99 app = Flask('yourapplication')100 app = Flask(__name__.split('.')[0])33 unmodified lines134 :param instance_path: An alternative instance path for the application.135 By default the folder ``'instance'`` next to the136 package or module is assumed to be the instance137 path.138- :param instance_relative_config: if set to `True` relative filenames138+ :param instance_relative_config: if set to ``True`` relative filenames139 for loading the config are assumed to140 be relative to the instance path instead141 of the application root.142 :param root_path: Flask by default will automatically calculate the path49 unmodified lines192 #:193 #: .. versionadded:: 1.0194 config_class = Config195 196- #: The debug flag. Set this to `True` to enable debugging of the196+ #: The debug flag. Set this to ``True`` to enable debugging of the197 #: application. In debug mode the debugger will kick in when an unhandled198 #: exception occurs and the integrated server will automatically reload199 #: the application if changes in the code are detected.200 #:201- #: This attribute can also be configured from the config with the `DEBUG`202- #: configuration key. Defaults to `False`.201+ #: This attribute can also be configured from the config with the ``DEBUG``202+ #: configuration key. Defaults to ``False``.203 debug = ConfigAttribute('DEBUG')204 205- #: The testing flag. Set this to `True` to enable the test mode of205+ #: The testing flag. Set this to ``True`` to enable the test mode of206 #: Flask extensions (and in the future probably also Flask itself).207 #: For example this might activate unittest helpers that have an208 #: additional runtime cost which should not be enabled by default.209 #:210 #: If this is enabled and PROPAGATE_EXCEPTIONS is not changed from the211 #: default it's implicitly enabled.212 #:213 #: This attribute can also be configured from the config with the214- #: `TESTING` configuration key. Defaults to `False`.214+ #: ``TESTING`` configuration key. Defaults to ``False``.215 testing = ConfigAttribute('TESTING')216 217 #: If a secret key is set, cryptographic components can use this to218 #: sign cookies and other things. Set this to a complex random value219 #: when you want to use the secure cookie for instance.220 #:221 #: This attribute can also be configured from the config with the222- #: `SECRET_KEY` configuration key. Defaults to `None`.222+ #: ``SECRET_KEY`` configuration key. Defaults to ``None``.223 secret_key = ConfigAttribute('SECRET_KEY')224 225 #: The secure cookie uses this for the name of the session cookie.226 #:227 #: This attribute can also be configured from the config with the228- #: `SESSION_COOKIE_NAME` configuration key. Defaults to ``'session'``228+ #: ``SESSION_COOKIE_NAME`` configuration key. Defaults to ``'session'``229 session_cookie_name = ConfigAttribute('SESSION_COOKIE_NAME')230 231 #: A :class:`~datetime.timedelta` which is used to set the expiration232 #: date of a permanent session. The default is 31 days which makes a233 #: permanent session survive for roughly one month.234 #:235 #: This attribute can also be configured from the config with the236- #: `PERMANENT_SESSION_LIFETIME` configuration key. Defaults to236+ #: ``PERMANENT_SESSION_LIFETIME`` configuration key. Defaults to237 #: ``timedelta(days=31)``238 permanent_session_lifetime = ConfigAttribute('PERMANENT_SESSION_LIFETIME',239 get_converter=_make_timedelta)240 3 unmodified lines244 #:245 #: .. versionadded:: 0.2246 #:247 #: This attribute can also be configured from the config with the248- #: `USE_X_SENDFILE` configuration key. Defaults to `False`.248+ #: ``USE_X_SENDFILE`` configuration key. Defaults to ``False``.249 use_x_sendfile = ConfigAttribute('USE_X_SENDFILE')250 251 #: The name of the logger to use. By default the logger name is the252 #: package name passed to the constructor.110 unmodified lines363 # support for the now deprecated `error_handlers` attribute. The364 # :attr:`error_handler_spec` shall be used now.365 self._error_handlers = {}366 367- #: A dictionary of all registered error handlers. The key is `None`367+ #: A dictionary of all registered error handlers. The key is ``None``368 #: for error handlers active on the application, otherwise the key is369 #: the name of the blueprint. Each key points to another dictionary370 #: where the key is the status code of the http exception. The371- #: special key `None` points to a list of tuples where the first item371+ #: special key ``None`` points to a list of tuples where the first item372 #: is the class for the instance check and the second the error handler373 #: function.374 #:375 #: To register a error handler, use the :meth:`errorhandler`2 unmodified lines378 379 #: A list of functions that are called when :meth:`url_for` raises a380 #: :exc:`~werkzeug.routing.BuildError`. Each function registered here381 #: is called with `error`, `endpoint` and `values`. If a function382- #: returns `None` or raises a `BuildError` the next function is382+ #: returns ``None`` or raises a :exc:`BuildError` the next function is383 #: tried.384 #:385 #: .. versionadded:: 0.9386 self.url_build_error_handlers = []387 388 #: A dictionary with lists of functions that should be called at the389 #: beginning of the request. The key of the dictionary is the name of390- #: the blueprint this function is active for, `None` for all requests.390+ #: the blueprint this function is active for, ``None`` for all requests.391 #: This can for example be used to open database connections or392 #: getting hold of the currently logged in user. To register a393 #: function here, use the :meth:`before_request` decorator.394 self.before_request_funcs = {}6 unmodified lines401 self.before_first_request_funcs = []402 403 #: A dictionary with lists of functions that should be called after404 #: each request. The key of the dictionary is the name of the blueprint405- #: this function is active for, `None` for all requests. This can for405+ #: this function is active for, ``None`` for all requests. This can for406 #: example be used to open database connections or getting hold of the407 #: currently logged in user. To register a function here, use the408 #: :meth:`after_request` decorator.409 self.after_request_funcs = {}410 411 #: A dictionary with lists of functions that are called after412 #: each request, even if an exception has occurred. The key of the413 #: dictionary is the name of the blueprint this function is active for,414- #: `None` for all requests. These functions are not allowed to modify414+ #: ``None`` for all requests. These functions are not allowed to modify415 #: the request, and their return values are ignored. If an exception416 #: occurred while processing the request, it gets passed to each417 #: teardown_request function. To register a function here, use the418 #: :meth:`teardown_request` decorator.11 unmodified lines430 431 #: A dictionary with lists of functions that can be used as URL432 #: value processor functions. Whenever a URL is built these functions433 #: are called to modify the dictionary of values in place. The key434- #: `None` here is used for application wide434+ #: ``None`` here is used for application wide435 #: callbacks, otherwise the key is the name of the blueprint.436 #: Each of these functions has the chance to modify the dictionary437 #:438 #: .. versionadded:: 0.7439 self.url_value_preprocessors = {}440 441 #: A dictionary with lists of functions that can be used as URL value442- #: preprocessors. The key `None` here is used for application wide442+ #: preprocessors. The key ``None`` here is used for application wide443 #: callbacks, otherwise the key is the name of the blueprint.444 #: Each of these functions has the chance to modify the dictionary445 #: of URL values before they are used as the keyword arguments of the446 #: view function. For each function registered this one should also4 unmodified lines451 self.url_default_functions = {}452 453 #: A dictionary with list of functions that are called without argument454 #: to populate the template context. The key of the dictionary is the455- #: name of the blueprint this function is active for, `None` for all455+ #: name of the blueprint this function is active for, ``None`` for all456 #: requests. Each returns a dictionary that the template context is457 #: updated with. To register a function here, use the458 #: :meth:`context_processor` decorator.459 self.template_context_processors = {62 unmodified lines522 endpoint='static',523 view_func=self.send_static_file)524 525 #: The click command line context for this application. Commands526- #: registered here show up in the ``flask`` command once the526+ #: registered here show up in the :command:`flask` command once the527 #: application has been discovered. The default commands are528 #: provided by Flask itself and can be overridden.529 #:530 #: This is an instance of a :class:`click.Group` object.28 unmodified lines559 return self.import_name560 561 @property562 def propagate_exceptions(self):563- """Returns the value of the `PROPAGATE_EXCEPTIONS` configuration563+ """Returns the value of the ``PROPAGATE_EXCEPTIONS`` configuration564 value in case it's set, otherwise a sensible default is returned.565 566 .. versionadded:: 0.7567 """3 unmodified lines571 return self.testing or self.debug572 573 @property574 def preserve_context_on_exception(self):575- """Returns the value of the `PRESERVE_CONTEXT_ON_EXCEPTION`575+ """Returns the value of the ``PRESERVE_CONTEXT_ON_EXCEPTION``576 configuration value in case it's set, otherwise a sensible default577 is returned.578 579 .. versionadded:: 0.731 unmodified lines611 return self.create_jinja_environment()612 613 @property614 def got_first_request(self):615- """This attribute is set to `True` if the application started615+ """This attribute is set to ``True`` if the application started616 handling the first request.617 618 .. versionadded:: 0.8619 """94 unmodified lines714 :meth:`create_jinja_environment` instead.715 """716 717 def select_jinja_autoescape(self, filename):718- """Returns `True` if autoescaping should be active for the given718+ """Returns ``True`` if autoescaping should be active for the given719 template name.720 721 .. versionadded:: 0.5722 """49 unmodified lines772 traceback screen active, but disable code execution.773 774 It is not recommended to use this function for development with775 automatic reloading as this is badly supported. Instead you should776- be using the ``flask`` command line script's ``runserver``776+ be using the :command:`flask` command line script's ``runserver``777 support.778 779 .. admonition:: Keep in Mind780 781 Flask will suppress any server error with a generic error page782 unless it is in debug mode. As such to enable just the783 interactive debugger without the code reloading, you have to784 invoke :meth:`run` with ``debug=True`` and ``use_reloader=False``.785- Setting ``use_debugger`` to `True` without being in debug mode785+ Setting ``use_debugger`` to ``True`` without being in debug mode786 won't catch any exceptions because there won't be any to787 catch.788 789 .. versionchanged:: 0.1047 unmodified lines837 838 app.testing = True839 client = app.test_client()840 841- The test client can be used in a `with` block to defer the closing down842- of the context until the end of the `with` block. This is useful if841+ The test client can be used in a ``with`` block to defer the closing down842+ of the context until the end of the ``with`` block. This is useful if843 you want to access the context locals for testing::844 845 with app.test_client() as c:846 rv = c.get('/?vodka=42')15 unmodified lines862 863 See :class:`~flask.testing.FlaskClient` for more information.864 865 .. versionchanged:: 0.4866- added support for `with` block usage for the client.866+ added support for ``with`` block usage for the client.867 868 .. versionadded:: 0.7869 The `use_cookies` parameter was added as well as the ability870 to override the client to be used by setting the96 unmodified lines967 .. versionchanged:: 0.2968 `view_func` parameter added.969 970 .. versionchanged:: 0.6971- `OPTIONS` is added automatically as method.971+ ``OPTIONS`` is added automatically as method.972 973 :param rule: the URL rule as string974 :param endpoint: the endpoint for the registered URL rule. Flask975 itself assumes the name of the view function as3 unmodified lines979 :param options: the options to be forwarded to the underlying980 :class:`~werkzeug.routing.Rule` object. A change981 to Werkzeug is handling of method options. methods982 is a list of methods this rule should be limited983- to (`GET`, `POST` etc.). By default a rule984- just listens for `GET` (and implicitly `HEAD`).985- Starting with Flask 0.6, `OPTIONS` is implicitly983+ to (``GET``, ``POST`` etc.). By default a rule984+ just listens for ``GET`` (and implicitly ``HEAD``).985+ Starting with Flask 0.6, ``OPTIONS`` is implicitly986 added and handled by the standard request handling.987 """988 if endpoint is None:989 endpoint = _endpoint_from_view_func(view_func)1 unmodified line991 methods = options.pop('methods', None)992 993 # if the methods are not given and the view_func object knows its994 # methods we can use that instead. If neither exists, we go with995- # a tuple of only `GET` as default.995+ # a tuple of only ``GET`` as default.996 if methods is None:997 methods = getattr(view_func, 'methods', None) or ('GET',)998 if isinstance(methods, string_types):999 raise TypeError('Allowed methods have to be iterables of strings, '47 unmodified lines1047 :param options: the options to be forwarded to the underlying1048 :class:`~werkzeug.routing.Rule` object. A change1049 to Werkzeug is handling of method options. methods1050 is a list of methods this rule should be limited1051- to (`GET`, `POST` etc.). By default a rule1052- just listens for `GET` (and implicitly `HEAD`).1053- Starting with Flask 0.6, `OPTIONS` is implicitly1051+ to (``GET``, ``POST`` etc.). By default a rule1052+ just listens for ``GET`` (and implicitly ``HEAD``).1053+ Starting with Flask 0.6, ``OPTIONS`` is implicitly1054 added and handled by the standard request handling.1055 """1056 def decorator(f):1057 endpoint = options.pop('endpoint', None)43 unmodified lines1101 Setting error handlers via assignments to :attr:`error_handler_spec`1102 however is discouraged as it requires fiddling with nested dictionaries1103 and the special case for arbitrary exception types.1104 1105- The first `None` refers to the active blueprint. If the error1106- handler should be application wide `None` shall be used.1105+ The first ``None`` refers to the active blueprint. If the error1106+ handler should be application wide ``None`` shall be used.1107 1108 .. versionadded:: 0.71109 Use :meth:`register_error_handler` instead of modifying1110 :attr:`error_handler_spec` directly, for application wide error280 unmodified lines1391 return handler(e)1392 1393 def trap_http_exception(self, e):1394 """Checks if an HTTP exception should be trapped or not. By default1395- this will return `False` for all exceptions except for a bad request1396- key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to `True`. It1397- also returns `True` if ``TRAP_HTTP_EXCEPTIONS`` is set to `True`.1395+ this will return ``False`` for all exceptions except for a bad request1396+ key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to ``True``. It1397+ also returns ``True`` if ``TRAP_HTTP_EXCEPTIONS`` is set to ``True``.1398 1399 This is called for all HTTP exceptions raised by a view function.1400- If it returns `True` for any exception the error handler for this1400+ If it returns ``True`` for any exception the error handler for this1401 exception is not called and it shows up as regular exception in the1402 traceback. This is helpful for debugging implicitly raised HTTP1403 exceptions.1404 153 unmodified lines1558 func()1559 self._got_first_request = True1560 1561 def make_default_options_response(self):1562- """This method is called to create the default `OPTIONS` response.1562+ """This method is called to create the default ``OPTIONS`` response.1563 This can be changed through subclassing to change the default1564- behavior of `OPTIONS` responses.1564+ behavior of ``OPTIONS`` responses.1565 1566 .. versionadded:: 0.71567 """1568 adapter = _request_ctx_stack.top.url_adapter14 unmodified lines1583 1584 def should_ignore_error(self, error):1585 """This is called to figure out if an error should be ignored1586 or not as far as the teardown system is concerned. If this1587- function returns `True` then the teardown handlers will not be1587+ function returns ``True`` then the teardown handlers will not be1588 passed the error.1589 1590 .. versionadded:: 0.101591 """219 unmodified lines1811 1812 def request_context(self, environ):1813 """Creates a :class:`~flask.ctx.RequestContext` from the given1814 environment and binds it to the current context. This must be used in1815- combination with the `with` statement because the request is only bound1816- to the current context for the duration of the `with` block.1815+ combination with the ``with`` statement because the request is only bound1816+ to the current context for the duration of the ``with`` block.1817 1818 Example usage::1819 1820 with app.request_context(environ):1821 do_something_with(request)1822 1823- The object returned can also be used without the `with` statement1823+ The object returned can also be used without the ``with`` statement1824 which is useful for working in the shell. The example above is1825 doing exactly the same as this code::1826 1827 ctx = app.request_context(environ)3 unmodified lines1831 finally:1832 ctx.pop()1833 1834 .. versionchanged:: 0.31835- Added support for non-with statement usage and `with` statement1835+ Added support for non-with statement usage and ``with`` statement1836 is now passed the ctx object.1837 1838 :param environ: a WSGI environment1839 """70 unmodified linesmodified:flask/blueprints.py+1 added-1 removed
40 unmodified lines41 subdomain = self.options.get('subdomain')42 if subdomain is None:43 subdomain = self.blueprint.subdomain44 45- #: The subdomain that the blueprint should be active for, `None`45+ #: The subdomain that the blueprint should be active for, ``None``46 #: otherwise.47 self.subdomain = subdomain48 49 url_prefix = self.options.get('url_prefix')365 unmodified linesmodified:flask/cli.py+2 added-2 removed
265 unmodified lines266 For information as of why this is useful see :ref:`custom-scripts`.267 268 :param add_default_commands: if this is True then the default run and269 shell commands wil be added.270- :param add_app_option: adds the default ``--app`` option. This gets270+ :param add_app_option: adds the default :option:`--app` option. This gets271 automatically disabled if a `create_app`272 callback is defined.273- :param add_debug_option: adds the default ``--debug`` option.273+ :param add_debug_option: adds the default :option:`--debug` option.274 :param create_app: an optional callback that is passed the script info275 and returns the loaded app.276 """277 215 unmodified linesmodified:flask/config.py+4 added-4 removed
91 unmodified lines92 93 app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS'])94 95 :param variable_name: name of the environment variable96- :param silent: set to `True` if you want silent failure for missing96+ :param silent: set to ``True`` if you want silent failure for missing97 files.98- :return: bool. `True` if able to load config, `False` otherwise.98+ :return: bool. ``True`` if able to load config, ``False`` otherwise.99 """100 rv = os.environ.get(variable_name)101 if not rv:102 if silent:12 unmodified lines115 116 :param filename: the filename of the config. This can either be an117 absolute filename or a filename relative to the118 root path.119- :param silent: set to `True` if you want silent failure for missing119+ :param silent: set to ``True`` if you want silent failure for missing120 files.121 122 .. versionadded:: 0.7123 `silent` parameter.48 unmodified lines172 173 :param filename: the filename of the JSON file. This can either be an174 absolute filename or a filename relative to the175 root path.176- :param silent: set to `True` if you want silent failure for missing176+ :param silent: set to ``True`` if you want silent failure for missing177 files.178 179 .. versionadded:: 1.0180 """78 unmodified linesmodified:flask/ctx.py+2 added-2 removed
207 unmodified lines208 The request context is automatically popped at the end of the request209 for you. In debug mode the request context is kept around if210 exceptions happen so that interactive debuggers have a chance to211 introspect the data. With 0.4 this can also be forced for requests212- that did not fail and outside of `DEBUG` mode. By setting213- ``'flask._preserve_context'`` to `True` on the WSGI environment the212+ that did not fail and outside of ``DEBUG`` mode. By setting213+ ``'flask._preserve_context'`` to ``True`` on the WSGI environment the214 context will not pop itself at the end of the request. This is used by215 the :meth:`~flask.Flask.test_client` for example to implement the216 deferred cleanup functionality.217 178 unmodified linesmodified:flask/helpers.py+21 added-21 removed
186 unmodified lines187 """Generates a URL to the given endpoint with the method provided.188 189 Variable arguments that are unknown to the target endpoint are appended190 to the generated URL as query arguments. If the value of a query argument191- is `None`, the whole pair is skipped. In case blueprints are active191+ is ``None``, the whole pair is skipped. In case blueprints are active192 you can shortcut references to the same blueprint by prefixing the193 local endpoint with a dot (``.``).194 195 This will reference the index function local to the current blueprint::6 unmodified lines202 errors through :attr:`Flask.url_build_error_handlers`. The `url_for`203 function results in a :exc:`~werkzeug.routing.BuildError` when the current204 app does not have a URL for the given endpoint and values. When it does, the205 :data:`~flask.current_app` calls its :attr:`~Flask.url_build_error_handlers` if206- it is not `None`, which can return a string to use as the result of206+ it is not ``None``, which can return a string to use as the result of207 `url_for` (instead of `url_for`'s default to raise the208 :exc:`~werkzeug.routing.BuildError` exception) or re-raise the exception.209 An example::210 32 unmodified lines243 :exc:`~werkzeug.routing.BuildError`.244 245 :param endpoint: the endpoint of the URL (name of the function)246 :param values: the variable arguments of the URL rule247- :param _external: if set to `True`, an absolute URL is generated. Server248- address can be changed via `SERVER_NAME` configuration variable which247+ :param _external: if set to ``True``, an absolute URL is generated. Server248+ address can be changed via ``SERVER_NAME`` configuration variable which249 defaults to `localhost`.250 :param _scheme: a string specifying the desired URL scheme. The `_external`251- parameter must be set to `True` or a `ValueError` is raised. The default251+ parameter must be set to ``True`` or a :exc:`ValueError` is raised. The default252 behavior uses the same scheme as the current request, or253 ``PREFERRED_URL_SCHEME`` from the :ref:`app configuration <config>` if no254 request context is available. As of Werkzeug 0.10, this also can be set255 to an empty string to build protocol-relative URLs.66 unmodified lines322 323 def get_template_attribute(template_name, attribute):324 """Loads a macro (or variable) a template exports. This can be used to325 invoke a macro from within Python code. If you for example have a326- template named `_cider.html` with the following contents:326+ template named :file:`_cider.html` with the following contents:327 328 .. sourcecode:: html+jinja329 330 {% macro hello(name) %}Hello {{ name }}!{% endmacro %}44 unmodified lines375 def get_flashed_messages(with_categories=False, category_filter=[]):376 """Pulls all flashed messages from the session and returns them.377 Further calls in the same request to the function will return378 the same messages. By default just the messages are returned,379- but when `with_categories` is set to `True`, the return value will379+ but when `with_categories` is set to ``True``, the return value will380 be a list of tuples in the form ``(category, message)`` instead.381 382 Filter the flashed messages to one or more categories by providing those383 categories in `category_filter`. This allows rendering categories in384 separate html blocks. The `with_categories` and `category_filter`385 arguments are distinct:386 387 * `with_categories` controls whether categories are returned with message388- text (`True` gives a tuple, where `False` gives just the message text).388+ text (``True`` gives a tuple, where ``False`` gives just the message text).389 * `category_filter` filters the messages down to only those matching the390 provided categories.391 392 See :ref:`message-flashing-pattern` for examples.3 unmodified lines396 397 .. versionchanged:: 0.9398 `category_filter` parameter added.399 400- :param with_categories: set to `True` to also receive categories.400+ :param with_categories: set to ``True`` to also receive categories.401 :param category_filter: whitelist of categories to limit return values402 """403 flashes = _request_ctx_stack.top.flashes404 if flashes is None:12 unmodified lines417 """Sends the contents of a file to the client. This will use the418 most efficient method available and configured. By default it will419 try to use the WSGI server's file_wrapper support. Alternatively420 you can set the application's :attr:`~Flask.use_x_sendfile` attribute421- to ``True`` to directly emit an `X-Sendfile` header. This however422- requires support of the underlying webserver for `X-Sendfile`.421+ to ``True`` to directly emit an ``X-Sendfile`` header. This however422+ requires support of the underlying webserver for ``X-Sendfile``.423 424 By default it will try to guess the mimetype for you, but you can425 also explicitly provide one. For extra security you probably want426 to send certain files as attachment (HTML for instance). The mimetype25 unmodified lines452 :param filename_or_fp: the filename of the file to send. This is453 relative to the :attr:`~Flask.root_path` if a454 relative path is specified.455 Alternatively a file object might be provided456- in which case `X-Sendfile` might not work and456+ in which case ``X-Sendfile`` might not work and457 fall back to the traditional method. Make sure458 that the file pointer is positioned at the start459 of data to send before calling :func:`send_file`.460 :param mimetype: the mimetype of the file if provided, otherwise461 auto detection happens.462- :param as_attachment: set to `True` if you want to send this file with462+ :param as_attachment: set to ``True`` if you want to send this file with463 a ``Content-Disposition: attachment`` header.464 :param attachment_filename: the filename for the attachment if it465 differs from the file's filename.466- :param add_etags: set to `False` to disable attaching of etags.467- :param conditional: set to `True` to enable conditional responses.466+ :param add_etags: set to ``False`` to disable attaching of etags.467+ :param conditional: set to ``True`` to enable conditional responses.468 469- :param cache_timeout: the timeout in seconds for the headers. When `None`469+ :param cache_timeout: the timeout in seconds for the headers. When ``None``470 (default), this value is set by471 :meth:`~Flask.get_send_file_max_age` of472 :data:`~flask.current_app`.473 """130 unmodified lines604 filename, as_attachment=True)605 606 .. admonition:: Sending files and Performance607 608- It is strongly recommended to activate either `X-Sendfile` support in608+ It is strongly recommended to activate either ``X-Sendfile`` support in609 your webserver or (if no authentication happens) to tell the webserver610 to serve files for the given path on its own without calling into the611 web application for improved performance.612 170 unmodified lines783 #: The name of the package or module. Do not change this once784 #: it was set by the constructor.785 self.import_name = import_name786 787- #: location of the templates. `None` if templates should not be787+ #: location of the templates. ``None`` if templates should not be788 #: exposed.789 self.template_folder = template_folder790 791 if root_path is None:25 unmodified lines817 del _get_static_url_path, _set_static_url_path818 819 @property820 def has_static_folder(self):821- """This is `True` if the package bound object's container has a821+ """This is ``True`` if the package bound object's container has a822 folder named ``'static'``.823 824 .. versionadded:: 0.5825 """16 unmodified lines842 the configuration of :data:`~flask.current_app`.843 844 Static file functions such as :func:`send_from_directory` use this845 function, and :func:`send_file` calls this function on846- :data:`~flask.current_app` when the given cache_timeout is `None`. If a846+ :data:`~flask.current_app` when the given cache_timeout is ``None``. If a847 cache_timeout is given in :func:`send_file`, that timeout is used;848 otherwise, this method is called.849 850 This allows subclasses to change the behavior when sending files based35 unmodified lines886 /templates887 /layout.html888 /index.html889 890- If you want to open the `schema.sql` file you would do the890+ If you want to open the :file:`schema.sql` file you would do the891 following::892 893 with app.open_resource('schema.sql') as f:894 contents = f.read()9 unmodified linesmodified:flask/json.py+2 added-2 removed
58 unmodified lines59 60 def default(self, o):61 """Implement this method in a subclass such that it returns a62 serializable object for ``o``, or calls the base implementation (to63- raise a ``TypeError``).63+ raise a :exc:`TypeError`).64 65 For example, to support arbitrary iterators, you could implement66 default like this::67 131 unmodified lines199 200 201 def jsonify(*args, **kwargs):202 """Creates a :class:`~flask.Response` with the JSON representation of203- the given arguments with an `application/json` mimetype. The arguments203+ the given arguments with an :mimetype:`application/json` mimetype. The arguments204 to this function are the same as to the :class:`dict` constructor.205 206 Example usage::207 43 unmodified linesmodified:flask/sessions.py+9 added-9 removed
40 unmodified lines41 del _get_permanent, _set_permanent42 43 #: some session backends can tell you if a session is new, but that is44 #: not necessarily guaranteed. Use with caution. The default mixin45- #: implementation just hardcodes `False` in.45+ #: implementation just hardcodes ``False`` in.46 new = False47 48- #: for some backends this will always be `True`, but some backends will48+ #: for some backends this will always be ``True``, but some backends will49 #: default this to false and detect changes in the dictionary for as50 #: long as changes do not happen on mutable structures in the session.51- #: The default mixin implementation just hardcodes `True` in.51+ #: The default mixin implementation just hardcodes ``True`` in.52 modified = True53 54 55 def _tag(value):92 unmodified lines148 149 class Session(dict, SessionMixin):150 pass151 152- If :meth:`open_session` returns `None` Flask will call into152+ If :meth:`open_session` returns ``None`` Flask will call into153 :meth:`make_null_session` to create a session that acts as replacement154 if the session support cannot work because some requirement is not155 fulfilled. The default :class:`NullSession` class that is created156 will complain that the secret key was not set.70 unmodified lines227 def get_cookie_path(self, app):228 """Returns the path for which the cookie should be valid. The229 default implementation uses the value from the ``SESSION_COOKIE_PATH``230 config var if it's set, and falls back to ``APPLICATION_ROOT`` or231- uses ``/`` if it's `None`.231+ uses ``/`` if it's ``None``.232 """233 return app.config['SESSION_COOKIE_PATH'] or \234 app.config['APPLICATION_ROOT'] or '/'235 11 unmodified lines247 return app.config['SESSION_COOKIE_SECURE']248 249 def get_expiration_time(self, app, session):250 """A helper method that returns an expiration date for the session251- or `None` if the session is linked to the browser session. The251+ or ``None`` if the session is linked to the browser session. The252 default implementation returns now + the permanent session253 lifetime configured on the application.254 """255 if session.permanent:3 unmodified lines259 """Indicates whether a cookie should be set now or not. This is260 used by session backends to figure out if they should emit a261 set-cookie header or not. The default behavior is controlled by262 the ``SESSION_REFRESH_EACH_REQUEST`` config variable. If263- it's set to `False` then a cookie is only set if the session is264- modified, if set to `True` it's always set if the session is263+ it's set to ``False`` then a cookie is only set if the session is264+ modified, if set to ``True`` it's always set if the session is265 permanent.266 267 This check is usually skipped if sessions get deleted.268 4 unmodified lines273 save_each = app.config['SESSION_REFRESH_EACH_REQUEST']274 return save_each and session.permanent275 276 def open_session(self, app, request):277- """This method has to be implemented and must either return `None`277+ """This method has to be implemented and must either return ``None``278 in case the loading failed because of a configuration error or an279 instance of a session object which implements a dictionary like280 interface + the methods and attributes on :class:`SessionMixin`.281 """84 unmodified linesmodified:flask/wrappers.py+11 added-11 removed
45 unmodified lines46 #: .. versionadded:: 0.647 url_rule = None48 49 #: A dict of view arguments that matched the request. If an exception50- #: happened when matching, this will be `None`.50+ #: happened when matching, this will be ``None``.51 view_args = None52 53 #: If matching the URL failed, this is the exception that will be54 #: raised / was raised as part of the request handling. This is6 unmodified lines61 _is_old_module = False62 63 @property64 def max_content_length(self):65- """Read-only view of the `MAX_CONTENT_LENGTH` config key."""65+ """Read-only view of the ``MAX_CONTENT_LENGTH`` config key."""66 ctx = _request_ctx_stack.top67 if ctx is not None:68 return ctx.app.config['MAX_CONTENT_LENGTH']69 1 unmodified line71 def endpoint(self):72 """The endpoint that matched the request. This in combination with73 :attr:`view_args` can be used to reconstruct the same or a74 modified URL. If an exception happened when matching, this will75- be `None`.75+ be ``None``.76 """77 if self.url_rule is not None:78 return self.url_rule.endpoint79 17 unmodified lines97 return self.url_rule.endpoint.rsplit('.', 1)[0]98 99 @property100 def json(self):101- """If the mimetype is `application/json` this will contain the102- parsed JSON data. Otherwise this will be `None`.101+ """If the mimetype is :mimetype:`application/json` this will contain the102+ parsed JSON data. Otherwise this will be ``None``.103 104 The :meth:`get_json` method should be used instead.105 """106 from warnings import warn4 unmodified lines111 @property112 def is_json(self):113 """Indicates if this request is JSON or not. By default a request114 is considered to include JSON data if the mimetype is115- ``application/json`` or ``application/*+json``.115+ :mimetype:`application/json` or :mimetype:`application/*+json`.116 117 .. versionadded:: 0.11118 """119 mt = self.mimetype6 unmodified lines126 def get_json(self, force=False, silent=False, cache=True):127 """Parses the incoming JSON request data and returns it. If128 parsing fails the :meth:`on_json_loading_failed` method on the129 request object will be invoked. By default this function will130- only load the json data if the mimetype is ``application/json``130+ only load the json data if the mimetype is :mimetype:`application/json`131 but this can be overridden by the `force` parameter.132 133- :param force: if set to `True` the mimetype is ignored.134- :param silent: if set to `True` this method will fail silently135- and return `None`.136- :param cache: if set to `True` the parsed JSON data is remembered133+ :param force: if set to ``True`` the mimetype is ignored.134+ :param silent: if set to ``True`` this method will fail silently135+ and return ``None``.136+ :param cache: if set to ``True`` the parsed JSON data is remembered137 on the request.138 """139 rv = getattr(self, '_cached_json', _missing)140 if rv is not _missing:61 unmodified linesmodified:CHANGES+15 added-15 removed
10 unmodified lines11 - Added `**kwargs` to :meth:`flask.Test.test_client` to support passing12 additional keyword arguments to the constructor of13 :attr:`flask.Flask.test_client_class`.14 - Added ``SESSION_REFRESH_EACH_REQUEST`` config key that controls the15- set-cookie behavior. If set to `True` a permanent session will be15+ set-cookie behavior. If set to ``True`` a permanent session will be16 refreshed each request and get their lifetime extended, if set to17- `False` it will only be modified if the session actually modifies.17+ ``False`` it will only be modified if the session actually modifies.18 Non permanent sessions are not affected by this and will always19 expire if the browser window closes.20 - Made Flask support custom JSON mimetypes for incoming data.21 - Added support for returning tuples in the form ``(response, headers)``5 unmodified lines27 can be configured with the new ``TEMPLATES_AUTO_RELOAD`` config key.28 - Added a workaround for a limitation in Python 3.3's namespace loader.29 - Added support for explicit root paths when using Python 3.3's namespace30 packages.31-- Added ``flask`` and the ``flask.cli`` module to start the local31+- Added :command:`flask` and the ``flask.cli`` module to start the local32 debug server through the click CLI system. This is recommended over the old33 ``flask.run()`` method as it works faster and more reliable due to a34 different design and also replaces ``Flask-Script``.35 - Error handlers that match specific classes are now checked first,146 unmodified lines182 - Logger now only returns the debug log setting if it was not set183 explicitly.184 - Unregister a circular dependency between the WSGI environment and185 the request object when shutting down the request. This means that186- environ ``werkzeug.request`` will be `None` after the response was186+ environ ``werkzeug.request`` will be ``None`` after the response was187 returned to the WSGI server but has the advantage that the garbage188 collector is not needed on CPython to tear down the request unless189 the user created circular dependencies themselves.190 - Session is now stored after callbacks so that if the session payload12 unmodified lines203 :meth:`flask.Blueprint.add_app_template_filter`.204 - The :func:`flask.get_flashed_messages` function now allows rendering flashed205 message categories in separate blocks, through a ``category_filter``206 argument.207-- The :meth:`flask.Flask.run` method now accepts `None` for `host` and `port`208- arguments, using default values when `None`. This allows for calling run207+- The :meth:`flask.Flask.run` method now accepts ``None`` for `host` and `port`208+ arguments, using default values when ``None``. This allows for calling run209 using configuration values, e.g. ``app.run(app.config.get('MYHOST'),210 app.config.get('MYPORT'))``, with proper behavior whether or not a config211 file is provided.212 - The :meth:`flask.render_template` method now accepts a either an iterable of112 unmodified lines325 Released on June 28th 2011, codename Grappa326 327 - Added :meth:`~flask.Flask.make_default_options_response`328 which can be used by subclasses to alter the default329- behavior for `OPTIONS` responses.329+ behavior for ``OPTIONS`` responses.330 - Unbound locals now raise a proper :exc:`RuntimeError` instead331 of an :exc:`AttributeError`.332 - Mimetype guessing and etag support based on file objects is now333 deprecated for :func:`flask.send_file` because it was unreliable.4 unmodified lines338 was not reliable and caused issues on Google's App Engine. Until339 1.0 the old behavior will continue to work but issue dependency340 warnings.341 - fixed a problem for Flask to run on jython.342-- added a `PROPAGATE_EXCEPTIONS` configuration variable that can be342+- added a ``PROPAGATE_EXCEPTIONS`` configuration variable that can be343 used to flip the setting of exception propagation which previously344- was linked to `DEBUG` alone and is now linked to either `DEBUG` or345- `TESTING`.344+ was linked to ``DEBUG`` alone and is now linked to either ``DEBUG`` or345+ ``TESTING``.346 - Flask no longer internally depends on rules being added through the347 `add_url_rule` function and can now also accept regular werkzeug348 rules added to the url map.349 - Added an `endpoint` method to the flask application object which28 unmodified lines378 -------------379 380 Bugfix release, released on December 31st 2010381 382-- Fixed an issue where the default `OPTIONS` response was383- not exposing all valid methods in the `Allow` header.382+- Fixed an issue where the default ``OPTIONS`` response was383+ not exposing all valid methods in the ``Allow`` header.384 - Jinja2 template loading syntax now allows "./" in front of385 a template load path. Previously this caused issues with386 module setups.387 - Fixed an issue where the subdomain setting for modules was61 unmodified lines449 Released on July 6th 2010, codename Calvados450 451 - fixed a bug with subdomains that was caused by the inability to452 specify the server name. The server name can now be set with453- the `SERVER_NAME` config key. This key is now also used to set453+ the ``SERVER_NAME`` config key. This key is now also used to set454 the session cookie cross-subdomain wide.455 - autoescaping is no longer active for all templates. Instead it456 is only active for ``.html``, ``.htm``, ``.xml`` and ``.xhtml``.457 Inside templates this behavior can be changed with the23 unmodified lines481 for a little longer. This can also be used to trigger custom482 requests that do not pop the request stack for testing.483 - because the Python standard library caches loggers, the name of484 the logger is configurable now to better support unittests.485-- added `TESTING` switch that can activate unittesting helpers.486-- the logger switches to `DEBUG` mode now if debug is enabled.485+- added ``TESTING`` switch that can activate unittesting helpers.486+- the logger switches to ``DEBUG`` mode now if debug is enabled.487 488 Version 0.3.1489 -------------490 48 unmodified lines