Skip to content
Myr

Extended quickstart docs for the headers

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 13005d7 · Browse files · 1 file+44 added−0 removed
This commit

State

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

Diff stats

1 file+44 added−0 removed

  • other:+44 added−0 removed

1 file+44 added−0 removed

modified:docs/quickstart.rst+44 added
619 unmodified lines
620just return strings from the view functions Flask will convert them into621response objects for you. If you explicitly want to do that you can use622the :meth:`~flask.make_response` function and then modify it.623624For this also see :ref:`about-responses`.625626Redirects and Errors627--------------------628
29 unmodified lines
658Note the ``404`` after the :func:`~flask.render_template` call. This659tells Flask that the status code of that page should be 404 which means660not found. By default 200 is assumed which translates to: all went well.661662.. _about-responses:663664About Responses665---------------666667The return value from a view function is automatically converted into a668response object for you. If the return value is a string it's converted669into a response object with the string as response body, an ``200 OK``670error code and a ``text/html`` mimetype. The logic that Flask applies to671converting return values into response objects is as follows:6726731. If a response object of the correct type is returned it's directly674 returned from the view.6752. If it's a string, a response object is created with that data and the676 default parameters.6773. If a tuple is returned the response object is created by passing the678 tuple as arguments to the response object's constructor.6794. If neither of that works, Flask will assume the return value is a680 valid WSGI application and converts that into a response object.681682If you want to get hold of the resulting response object inside the view683you can use the :func:`~flask.make_response` function.684685Imagine you have a view like this:686687.. sourcecode:: python688689 @app.errorhandler(404)690 def not_found(error):691 return render_template('error.html'), 404692693You just need to wrap the return expression with694:func:`~flask.make_response` and get the result object to modify it, then695return it:696697.. sourcecode:: python698699 @app.errorhandler(404)700 def not_found(error):701 resp = make_response(render_template('error.html'), 404)702 resp.headers['X-Something'] = 'A value'703 return resp704705.. _sessions:706707Sessions708--------
112 unmodified lines