Heavily improved documentation
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 4e1b3e1 · Browse files · 10 files·+486 added−44 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+486 added−44 removed
- other:+486 added−44 removed
Provenance
- Commit
05f36c7- Tree
ad76d0d- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
4e1b3e1
10 files changed+486 added−44 removed
modified:docs/_templates/sidebarintro.html+5 added
3 unmodified lines4567891011123 unmodified lines looking at the documentation of the development version. Things are not stable yet, but if you have some feedback, <a href="mailto:armin.ronacher@active-4.com">let me know</a>.</p><h3>Useful Links</h3><ul> <li><a href="http://pypi.python.org/pypi/Flask">Flask @ PyPI</a></li> <li><a href="http://github.com/mitsuhiko/flask">Flask @ github</a></li></ul>modified:docs/_themes/flasky/static/flasky.css_t+74 added-20 removed
14 unmodified lines15 16 body {17 font-family: 'Georgia', serif;18 font-size: 100%;19- background-color: #111;19+ background-color: #555;20 color: #555;21 margin: 0;22 padding: 0;23 }22 unmodified lines46 font-size: 0.9em;47 }48 49 div.footer {50- color: #555;51- width: 100%;52- padding: 13px 0;53- text-align: center;54- font-size: 75%;50+ color: #ccc;51+ padding: 10px;52+ font-size: 0.8em;53 }54 55 div.footer a {58- color: #444;56+ color: white;57 text-decoration: underline;58 }59 60 div.related {74 unmodified lines135 136 /* -- body styles ----------------------------------------------------------- */137 138 a {141- color: #003B55;139+ color: #004B6B;140 text-decoration: none;141 }142 143 a:hover {12 unmodified lines156 font-weight: normal;157 color: #212224;158 margin: 30px 0px 10px 0px;159 padding: 8px 0 5px 10px;162- text-shadow: 0px 1px 0 white160+ text-shadow: 0px 1px 0 white;161 }162 163 div.body h1 { border-top: 20px solid white; margin-top: 0; font-size: 200%; }164 div.body h2 { font-size: 150%; background-color: #ddd; }2 unmodified lines167 div.body h5 { font-size: 100%; background-color: #eee; }168 div.body h6 { font-size: 100%; background-color: #eee; }169 170 a.headerlink {173- color: #c60f0f;171+ color: white;172 padding: 0 4px;173 text-decoration: none;174 }175 176 a.headerlink:hover {179- background-color: #c60f0f;180- color: white;177+ color: #444;178+ background: #eaeaea;179 }180 181 div.body p, div.body dd, div.body li {182 line-height: 1.5em;32 unmodified lines215 216 p.admonition-title:after {217 content: ":";218 }219+220+pre, tt {221+ font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace;222+ font-size: 0.9em;223+}224+225+tt.descname, tt.descclassname {226+ font-size: 0.95em;227+ -webkit-box-shadow: none;228+ -moz-box-shadow: none;229+}230+231+tt.descname {232+ padding-right: 0.08em;233+}234+235+table.docutils {236+ border: 1px solid #888;237+ -webkit-box-shadow: 2px 2px 1px #d8d8d8;238+ -moz-box-shadow: 2px 2px 1px #d8d8d8;239+}240+241+table.docutils td, table.docutils th {242+ border: 1px solid #888;243+ padding: 0.25em 0.7em;244+}245+246+table.field-list {247+ border: none;248+ -webkit-box-shadow: none;249+ -moz-box-shadow: none;250+}251+252+table.field-list th {253+ padding: 0 0.8em 0 0;254+}255+256+table.field-list td {257+ padding: 0;258+}259 260 pre {261+ background: #FDFDFD;262 padding: 10px;263 color: #222;225- line-height: 1.2em;226- border: 1px solid #C6C9CB;227- font-size: 1.1em;228- margin: 1.5em 0 1.5em 0;229- -webkit-box-shadow: 1px 1px 1px #d8d8d8;230- -moz-box-shadow: 1px 1px 1px #d8d8d8;264+ line-height: 1.3em;265+ border: 1px solid #f9f9f9;266+ margin: 1.5em 3px 1.5em 0;267+ -webkit-box-shadow: 2px 2px 1px #d8d8d8;268+ -moz-box-shadow: 2px 2px 1px #d8d8d8;269 }270 271 tt {272 background-color: #ecf0f3;273 color: #222;274 /* padding: 1px 2px; */237- font-size: 1.1em;238- font-family: monospace;275+ -webkit-box-shadow: 1px 1px 1px #d8d8d8;276+ -moz-box-shadow: 1px 1px 1px #d8d8d8;277 }278+279+tt.xref, a tt {280+ background-color: #FBFBFB;281+}282+283+a:hover tt {284+ background: #EEE;285+}286+287+div.document + div.related {288+ background: #aaa;289+}290+291+div.document + div.related a {292+ color: white;293+}modified:docs/api.rst+7 added-1 removed
161 unmodified lines162 ----------------------------163 164 .. autofunction:: url_for165 166-.. autofunction:: abort166+.. function:: abort(code)167 168+ Raises an :exc:`~werkzeug.exception.HTTPException` for the given169+ status code. For example to abort request handling with a page not170+ found exception, you would call ``abort(404)``.171+172+ :param code: the HTTP error code.173+174 .. autofunction:: redirect175 176 .. autofunction:: escape177 16 unmodified linesadded:docs/deploying.rst+266 added
1+Deployment Options2+==================3+4+Depending on what you have available there are multiple ways to run Flask5+applications. A very common method is to use the builtin server during6+development and maybe behind a proxy for simple applications, but there7+are more options available.8+9+If you have a different WSGI server look up the server documentation about10+how to use a WSGI app with it. Just remember that your application object11+is the actual WSGI application.12+13+14+FastCGI15+-------16+17+A very popular deployment setup on servers like `lighttpd`_ and `nginx`_18+is FastCGI. To use your WSGI application with any of them you will need19+a FastCGI server first.20+21+The most popular one is `flup`_ which we will use for this guide. Make22+sure to have it installed.23+24+Creating a `.fcgi` file25+```````````````````````26+27+First you need to create the FastCGI server file. Let's call it28+`yourapplication.fcgi`::29+30+ #!/usr/bin/python31+ from flup.server.fcgi import WSGIServer32+ from yourapplication import app33+34+ WSGIServer(app).run()35+36+This is enough for Apache to work, however lighttpd and nginx need a37+socket to communicate with the FastCGI server. For that to work you38+need to pass the path to the socket to the39+:class:`~flup.server.fcgi.WSGIServer`::40+41+ WSGIServer(application, bindAddress='/path/to/fcgi.sock').run()42+43+The path has to be the exact same path you define in the server44+config.45+46+Save the `yourapplication.fcgi` file somewhere you will find it again.47+It makes sense to have that in `/var/www/yourapplication` or something48+similar.49+50+Make sure to set the executable bit on that file so that the servers51+can execute it::52+53+ # chmod +x /var/www/yourapplication/yourapplication.fcgi54+55+Configuring lighttpd56+````````````````````57+58+A basic FastCGI configuration for lighttpd looks like that::59+60+ fastcgi.server = ("/yourapplication" =>61+ "yourapplication" => (62+ "socket" => "/tmp/yourapplication-fcgi.sock",63+ "bin-path" => "/var/www/yourapplication/yourapplication.fcgi",64+ "check-local" => "disable"65+ )66+ )67+68+This configuration binds the application to `/yourapplication`. If you69+want the application to work in the URL root you have to work around a70+lighttpd bug with the `~werkzeug.contrib.fixers.LighttpdCGIRootFix` middleware.71+72+Make sure to apply it only if you are mounting the application the URL73+root.74+75+Configuring nginx76+`````````````````77+78+Installing FastCGI applications on nginx is a bit tricky because by default79+some FastCGI parameters are not properly forwarded.80+81+A basic FastCGI configuration for nginx looks like this::82+83+ location /yourapplication/ {84+ include fastcgi_params;85+ if ($uri ~ ^/yourapplication/(.*)?) {86+ set $path_url $1;87+ }88+ fastcgi_param PATH_INFO $path_url;89+ fastcgi_param SCRIPT_NAME /yourapplication;90+ fastcgi_pass unix:/tmp/yourapplication-fcgi.sock;91+ }92+93+This configuration binds the application to `/yourapplication`. If you want94+to have it in the URL root it's a bit easier because you don't have to figure95+out how to calculate `PATH_INFO` and `SCRIPT_NAME`::96+97+ location /yourapplication/ {98+ include fastcgi_params;99+ fastcgi_param PATH_INFO $fastcgi_script_name;100+ fastcgi_param SCRIPT_NAME "";101+ fastcgi_pass unix:/tmp/yourapplication-fcgi.sock;102+ }103+104+Since Nginx doesn't load FastCGI apps, you have to do it by yourself. You105+can either write an `init.d` script for that or execute it inside a screen106+session::107+108+ $ screen109+ $ /var/www/yourapplication/yourapplication.fcgi110+111+Debugging112+`````````113+114+FastCGI deployments tend to be hard to debug on most webservers. Very often the115+only thing the server log tells you is something along the lines of "premature116+end of headers". In order to debug the application the only thing that can117+really give you ideas why it breaks is switching to the correct user and118+executing the application by hand.119+120+This example assumes your application is called `application.fcgi` and that your121+webserver user is `www-data`::122+123+ $ su www-data124+ $ cd /var/www/yourapplication125+ $ python application.fcgi126+ Traceback (most recent call last):127+ File "yourapplication.fcg", line 4, in <module>128+ ImportError: No module named yourapplication129+130+In this case the error seems to be "yourapplication" not being on the python131+path. Common problems are:132+133+- relative paths being used. Don't rely on the current working directory134+- the code depending on environment variables that are not set by the135+ web server.136+- different python interpreters being used.137+138+.. _lighttpd: http://www.lighttpd.net/139+.. _nginx: http://nginx.net/140+.. _flup: http://trac.saddi.com/flup141+142+143+mod_wsgi (Apache)144+-----------------145+146+If you are using the `Apache`_ webserver you should consider using `mod_wsgi`_.147+148+.. _Apache: http://httpd.apache.org/149+150+Installing `mod_wsgi`151+`````````````````````152+153+If you don't have `mod_wsgi` installed yet you have to either install it using154+a package manager or compile it yourself.155+156+The mod_wsgi `installation instructions`_ cover installation instructions for157+source installations on UNIX systems.158+159+If you are using ubuntu / debian you can apt-get it and activate it as follows::160+161+ # apt-get install libapache2-mod-wsgi162+163+On FreeBSD install `mod_wsgi` by compiling the `www/mod_wsgi` port or by using164+pkg_add::165+166+ # pkg_add -r mod_wsgi167+168+If you are using pkgsrc you can install `mod_wsgi` by compiling the169+`www/ap2-wsgi` package.170+171+If you encounter segfaulting child processes after the first apache reload you172+can safely ignore them. Just restart the server.173+174+Creating a `.wsgi` file175+```````````````````````176+177+To run your application you need a `yourapplication.wsgi` file. This file178+contains the code `mod_wsgi` is executing on startup to get the application179+object. The object called `application` in that file is then used as180+application.181+182+For most applications the following file should be sufficient::183+184+ from yourapplication import app as application185+186+If you don't have a factory function for application creation but a singleton187+instance you can directly import that one as `application`.188+189+Store that file somewhere where you will find it again (eg:190+`/var/www/yourapplication`) and make sure that `yourapplication` and all191+the libraries that are in use are on the python load path. If you don't192+want to install it system wide consider using a `virtual python`_ instance.193+194+Configuring Apache195+``````````````````196+197+The last thing you have to do is to create an Apache configuration file for198+your application. In this example we are telling `mod_wsgi` to execute the199+application under a different user for security reasons:200+201+.. sourcecode:: apache202+203+ <VirtualHost *>204+ ServerName example.com205+206+ WSGIDaemonProcess yourapplication user=user1 group=group1 processes=1 threads=5207+ WSGIScriptAlias / /var/www/yourapplication/yourapplication.wsgi208+209+ <Directory /var/www/yourapplication>210+ WSGIProcessGroup yourapplication211+ WSGIApplicationGroup %{GLOBAL}212+ Order deny,allow213+ Allow from all214+ </Directory>215+ </VirtualHost>216+217+For more information consult the `mod_wsgi wiki`_.218+219+.. _mod_wsgi: http://code.google.com/p/modwsgi/220+.. _installation instructions: http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide221+.. _virtual python: http://pypi.python.org/pypi/virtualenv222+.. _mod_wsgi wiki: http://code.google.com/p/modwsgi/wiki/223+224+225+CGI226+---227+228+If all other deployment methods do not work, CGI will work for sure. CGI229+is supported by all major browsers but usually has a less-than-optimal230+performance.231+232+This is also the way you can use a Flask application on Google's233+`AppEngine`_, there however the execution does happen in a CGI-like234+environment. The application's performance is unaffected because of that.235+236+.. _AppEngine: http://code.google.com/appengine/237+238+Creating a `.cgi` file239+``````````````````````240+241+First you need to create the CGI application file. Let's call it242+`yourapplication.cgi`::243+244+ #!/usr/bin/python245+ from wsgiref.handlers import CGIHandler246+ from yourapplication import app247+248+ CGIHandler().run(app)249+250+If you're running Python 2.4 you will need the :mod:`wsgiref` package. Python251+2.5 and higher ship this as part of the standard library.252+253+Server Setup254+````````````255+256+Usually there are two ways to configure the server. Either just copy the257+`.cgi` into a `cgi-bin` (and use `mod_rerwite` or something similar to258+rewrite the URL) or let the server point to the file directly.259+260+In Apache for example you can put a like like this into the config:261+262+.. sourcecode:: apache263+264+ ScriptName /app /path/to/the/application.cgi265+266+For more information consult the documentation of your webserver.modified:docs/flaskext.py+5 added-15 removed
14 unmodified lines15 Error: "#a40000 border:#ef2929", # class: 'err'16 Other: "#000000", # class 'x'17 18 Comment: "italic #8f5902", # class: 'c'19- Comment.Multiline: "italic #8f5902", # class: 'cm'20- Comment.Preproc: "italic #8f5902", # class: 'cp'21- Comment.Single: "italic #8f5902", # class: 'c1'22- Comment.Special: "italic #8f5902", # class: 'cs'19+ Comment.Preproc: "noitalic", # class: 'cp'20 21 Keyword: "bold #004461", # class: 'k'22 Keyword.Constant: "bold #004461", # class: 'kc'23 Keyword.Declaration: "bold #004461", # class: 'kd'15 unmodified lines39 Name.Builtin: "#004461", # class: 'nb'40 Name.Builtin.Pseudo: "#3465a4", # class: 'bp'41 Name.Class: "#000000", # class: 'nc' - to be revised42 Name.Constant: "#000000", # class: 'no' - to be revised46- Name.Decorator: "#999", # class: 'nd' - to be revised43+ Name.Decorator: "#888", # class: 'nd' - to be revised44 Name.Entity: "#ce5c00", # class: 'ni'45 Name.Exception: "bold #cc0000", # class: 'ne'46 Name.Function: "#000000", # class: 'nf'47 Name.Property: "#000000", # class: 'py'5 unmodified lines53 Name.Variable.Class: "#000000", # class: 'vc' - to be revised54 Name.Variable.Global: "#000000", # class: 'vg' - to be revised55 Name.Variable.Instance: "#000000", # class: 'vi' - to be revised56 60- # since the tango light blue does not show up well in text, we choose61- # a pure blue instead.62- Number: "bold #0000cf", # class: 'm'57+ Number: "#990000", # class: 'm'63- Number.Float: "bold #0000cf", # class: 'mf'64- Number.Hex: "bold #0000cf", # class: 'mh'65- Number.Integer: "bold #0000cf", # class: 'mi'66- Number.Integer.Long: "bold #0000cf", # class: 'il'67- Number.Oct: "bold #0000cf", # class: 'mo'58 59 Literal: "#000000", # class: 'l'60 Literal.Date: "#000000", # class: 'ld'61 15 unmodified lines77 Generic.Emph: "italic #000000", # class: 'ge'78 Generic.Error: "#ef2929", # class: 'gr'79 Generic.Heading: "bold #000080", # class: 'gh'80 Generic.Inserted: "#00A000", # class: 'gi'91- Generic.Output: "italic #000000", # class: 'go'92- Generic.Prompt: "#8f5902", # class: 'gp'81+ Generic.Output: "#888", # class: 'go'82+ Generic.Prompt: "#745334", # class: 'gp'83 Generic.Strong: "bold #000000", # class: 'gs'84 Generic.Subheading: "bold #800080", # class: 'gu'85 Generic.Traceback: "bold #a40000", # class: 'gt'86 }modified:docs/foreword.rst+9 added
34 unmodified lines35 something the framework just cannot do for you without modification.36 If you are ever in that situation, check out the :ref:`becomingbig`37 chapter.38 39+A Framework and An Example40+--------------------------41+42+Flask is not only a microframework, it is also an example. Based on43+Flask, there will be a series of blog posts that explain how to create a44+framework. Flask itself is just one way to implement a framework on top45+of existing libraries. Unlike many other microframeworks Flask does not46+try to implement anything on its own, it reuses existing code.47+48 Target Audience49 ---------------50 51 Is Flask for you? Is your application small-ish (less than 4000 lines of15 unmodified linesmodified:docs/index.rst+1 added
18 unmodified lines19 installation20 quickstart21 patterns22 api23+ deploying24 becomingbigmodified:docs/installation.rst+39 added-4 removed
39 unmodified lines40 41 If you are on OS X or Linux chances are that one of the following two42 commands will for for you::43 44- sudo easy_install virtualenv44+ $ sudo easy_install virtualenv45 46 or even better::47 48- sudo pip install virtualenv48+ $ sudo pip install virtualenv49 50 Changes are you have virtualenv installed on your system then. Maybe it's51 even in your package manager (on ubuntu try ``sudo apt-get install52 python-virtualenv``).53 54-On windows, just installed virtualenv from the `Python Package Index55-<http://pypi.python.org/pypi/virtualenv>`_.54+If you are on Windows and missing the `easy_install` command you have to55+install it first. Check the :ref:`windows-easy-install` section for more56+information about how to do that.57 58 So now that you have virtualenv running just fire up a shell and create59 your own environment. I usually create a folder and a `env` folder60 within::40 unmodified lines101 102 Now I really don't recommend this way on using Flask, but you can do that103 of course as well. Download the `dip` zipfile from the website and unzip104 it next to your application.105+106+.. _windows-easy-install:107+108+`easy_install` on Windows109+-------------------------110+111+On Windows installation of `easy_install` is a little bit tricker because112+on Windows slightly different rules apply, but it's not a biggy. The113+easiest way to accomplish that is downloading the `ez_setup.py`_ file and114+running it. (Double clicking should do the trick)115+116+Once you have done that it's important to add the `easy_install` command117+and other Python scripts to the path. To do that you have to add the118+Python installation's Script folder to the `PATH` variable.119+120+To do that, click right on your "Computer" desktop icon and click121+"Properties". On Windows Vista and Windows 7 then click on "Advanced System122+settings", on Windows XP click on the "Advanced" tab instead. Then click123+on the "Environment variables" button and double click on the "Path"124+variable in the "System variables" section.125+126+There append the path of your Python interpreter's Script folder to the127+end of the last (make sure you delimit it from existing values with a128+semicolon). Assuming you are using Python 2.6 on the default path, add129+the following value::130+131+ ;C:\Python26\Scripts132+133+Then you are done. To check if it worked, open the cmd and execute134+"easy_install". If you have UAC enabled it should prompt you for admin135+privileges.136+137+138+.. _ez_setup.py: http://peak.telecommunity.com/dist/ez_setup.pymodified:docs/quickstart.rst+8 added-3 removed
21 unmodified lines22 23 if __name__ == '__main__':24 app.run()25 26-If you now start that application with your Python interpreter and head27-over to `http://localhost:5000/ <http://localhost:5000/>`_, you should see28-your hello world application.26+Just save it as `hello.py` or something similar and run it with your27+Python interpreter::28 29+ $ python hello.py30+ * Running on http://localhost:5000/31+32+Head over to `http://localhost:5000/ <http://localhost:5000/>`_, you should33+see your hello world greeting.34+35 So what did that code do?36 37 1. first we imported the :class:`~flask.Flask` class. An instance of this38 class will be our WSGI application.465 unmodified linesmodified:flask.py+72 added-1 removed
77 unmodified lines78 def flash(message):79 """Flashes a message to the next request. In order to remove the80 flashed message from the session and to display it to the user,81 the template has to call :func:`get_flashed_messages`.82+83+ :param message: the message to be flashed.84 """85 session['_flashes'] = (session.get('_flashes', [])) + [message]86 87 11 unmodified lines99 100 def render_template(template_name, **context):101 """Renders a template from the template folder with the given102 context.103+104+ :param template_name: the name of the template to be rendered105+ :param context: the variables that should be available in the106+ context of the template.107 """108 current_app.update_template_context(context)109 return current_app.jinja_env.get_template(template_name).render(context)110 111 112 def render_template_string(source, **context):113 """Renders a template from the given template source string114 with the given context.115+116+ :param template_name: the sourcecode of the template to be117+ rendered118+ :param context: the variables that should be available in the119+ context of the template.120 """121 current_app.update_template_context(context)122 return current_app.jinja_env.from_string(source).render(context)123 108 unmodified lines232 233 def update_template_context(self, context):234 """Update the template context with some commonly used variables.235 This injects request, session and g into the template context.236+237+ :param context: the context as a dictionary that is updated in place238+ to add extra variables.239 """240 reqctx = _request_ctx_stack.top241 context['request'] = reqctx.request242 context['session'] = reqctx.session2 unmodified lines245 def run(self, host='localhost', port=5000, **options):246 """Runs the application on a local development server. If the247 :attr:`debug` flag is set the server will automatically reload248 for code changes and show a debugger in case an exception happened.249+250+ :param host: the hostname to listen on. set this to ``'0.0.0.0'``251+ to have the server available externally as well.252+ :param port: the port of the webserver253+ :param options: the options to be forwarded to the underlying254+ Werkzeug server. See :func:`werkzeug.run_simple`255+ for more information.256 """257 from werkzeug import run_simple258 if 'debug' in options:259 self.debug = options.pop('debug')28 unmodified lines288 289 with app.open_resource('schema.sql') as f:290 contents = f.read()291 do_something_with(contents)292+293+ :param resource: the name of the resource. To access resources within294+ subfolders use forward slashes as separator.295 """296 return pkg_resources.resource_stream(self.package_name, resource)297 298 def open_session(self, request):299 """Creates or opens a new session. Default implementation stores all300 session data in a signed cookie. This requires that the301 :attr:`secret_key` is set.302+303+ :param request: an instance of :attr:`request_class`.304 """305 key = self.secret_key306 if key is not None:307 return SecureCookie.load_cookie(request, self.session_cookie_name,1 unmodified line309 310 def save_session(self, session, response):311 """Saves the session if it needs updates. For the default312 implementation, check :meth:`open_session`.313+314+ :param session: the session to be saved (a315+ :class:`~werkzeug.contrib.securecookie.SecureCookie`316+ object)317+ :param request: an instance of :attr:`response_class`318 """319 if session is not None:320 session.save_cookie(response, self.session_cookie_name)321 12 unmodified lines334 def index():335 pass336 app.add_url_rule('index', '/')337 app.view_functions['index'] = index338+339+ :param rule: the URL rule as string340+ :param endpoint: the endpoint for the registered URL rule. Flask341+ itself assumes the name of the view function as342+ endpoint343+ :param options: the options to be forwarded to the underlying344+ :class:`~werkzeug.routing.Rule` object345 """346 options['endpoint'] = endpoint347 options.setdefault('methods', ('GET',))348 self.url_map.add(Rule(rule, **options))51 unmodified lines400 401 The :meth:`route` decorator accepts a couple of other arguments402 as well:403 404+ :param rule: the URL rule as string405 :param methods: a list of methods this rule should be limited406 to (``GET``, ``POST`` etc.). By default a rule407 just listens for ``GET`` (and implicitly ``HEAD``).408 :param subdomain: specifies the rule for the subdoain in case409 subdomain matching is in use.410 :param strict_slashes: can be used to disable the strict slashes411 setting for this rule. See above.412+ :param options: other options to be forwarded to the underlying413+ :class:`~werkzeug.routing.Rule` object.414 """415 def decorator(f):416 self.add_url_rule(rule, f.__name__, **options)417 self.view_functions[f.__name__] = f14 unmodified lines432 433 def page_not_found():434 return 'This page does not exist', 404435 app.error_handlers[404] = page_not_found436+437+ :param code: the code as integer for the handler438 """439 def decorator(f):440 self.error_handlers[code] = f441 return f40 unmodified lines482 483 def make_response(self, rv):484 """Converts the return value from a view function to a real485 response object that is an instance of :attr:`response_class`.486+487+ The following types are allowd for `rv`:488+489+ ======================= ===========================================490+ :attr:`response_class` the object is returned unchanged491+ :class:`str` a response object is created with the492+ string as body493+ :class:`unicode` a response object is created with the494+ string encoded to utf-8 as body495+ :class:`tuple` the response object is created with the496+ contents of the tuple as arguments497+ a WSGI function the function is called as WSGI application498+ and buffered as response object499+ ======================= ===========================================500+501+ :param rv: the return value from the view function502 """503 if isinstance(rv, self.response_class):504 return rv505 if isinstance(rv, basestring):16 unmodified lines522 523 def process_response(self, response):524 """Can be overridden in order to modify the response object525 before it's sent to the WSGI server.526+527+ :param response: a :attr:`response_class` object.528+ :return: a new response object or the same, has to be an529+ instance of :attr:`response_class`.530 """531 session = _request_ctx_stack.top.session532 if session is not None:533 self.save_session(session, response)5 unmodified lines539 """The actual WSGI application. This is not implemented in540 `__call__` so that middlewares can be applied:541 542 app.wsgi_app = MyMiddleware(app.wsgi_app)543+544+ :param environ: a WSGI environment545+ :param start_response: a callable accepting a status code,546+ a list of headers and an optional547+ exception context to start the response548 """549 with self.request_context(environ):550 rv = self.preprocess_request()551 if rv is None:12 unmodified lines564 Example usage::565 566 with app.request_context(environ):567 do_something_with(request)568+569+ :params environ: a WSGI environment570 """571 _request_ctx_stack.push(_RequestContext(self, environ))572 try:573 yield1 unmodified line575 _request_ctx_stack.pop()576 577 def test_request_context(self, *args, **kwargs):578 """Creates a WSGI environment from the given values (see509- :func:`werkzeug.create_environ` for more information).579+ :func:`werkzeug.create_environ` for more information, this580+ function accepts the same arguments).581 """582 return self.request_context(create_environ(*args, **kwargs))583 584 def __call__(self, environ, start_response):10 unmodified lines