diff --git a/docs/api.rst b/docs/api.rst index 98614ead..e3439393 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -19,6 +19,8 @@ Application Object Incoming Request Data --------------------- +.. autoclass:: Request + .. class:: request To access incoming request data, you can use the global `request` @@ -104,6 +106,20 @@ Incoming Request Data `root_url` ``http://www.example.com/myapplication/`` ============= ====================================================== +Response Objects +---------------- + +.. autoclass:: flask.Response + :members: set_cookie, data, mimetype + + .. attribute:: headers + + A :class:`Headers` object representing the response headers. + + .. attribute:: status_code + + The response status as integer. + Sessions -------- diff --git a/docs/index.rst b/docs/index.rst index 81528203..5c622fe6 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -21,4 +21,5 @@ you want to dive into all the internal parts of Flask, check out the patterns api deploying + testing becomingbig diff --git a/flask.py b/flask.py index 21858f5e..0c3a8b32 100644 --- a/flask.py +++ b/flask.py @@ -15,8 +15,8 @@ import pkg_resources from threading import local from contextlib import contextmanager from jinja2 import Environment, PackageLoader -from werkzeug import Request, Response, LocalStack, LocalProxy, \ - create_environ, cached_property +from werkzeug import Request as RequestBase, Response as ResponseBase, \ + LocalStack, LocalProxy, create_environ, cached_property from werkzeug.routing import Map, Rule from werkzeug.exceptions import HTTPException, InternalServerError from werkzeug.contrib.securecookie import SecureCookie @@ -27,21 +27,29 @@ from werkzeug import abort, redirect from jinja2 import Markup, escape -class FlaskRequest(Request): +class Request(RequestBase): """The request object used by default in flask. Remembers the matched endpoint and view arguments. + + It is what ends up as :class:`~flask.request`. If you want to replace + the request object used you can subclass this and set + :attr:`~flask.Flask.request_class` to your subclass. """ def __init__(self, environ): - Request.__init__(self, environ) + RequestBase.__init__(self, environ) self.endpoint = None self.view_args = None -class FlaskResponse(Response): +class Response(ResponseBase): """The response object that is used by default in flask. Works like the response object from Werkzeug but is set to have a HTML mimetype by - default. + default. Quite often you don't have to create this object yourself because + :meth:`~flask.Flask.make_response` will take care of that for you. + + If you want to replace the response object used you can subclass this and + set :attr:`~flask.Flask.request_class` to your subclass. """ default_mimetype = 'text/html' @@ -142,11 +150,13 @@ class Flask(object): app = Flask(__name__) """ - #: the class that is used for request objects - request_class = FlaskRequest + #: the class that is used for request objects. See :class:`~flask.request` + #: for more information. + request_class = Request - #: the class that is used for response objects - response_class = FlaskResponse + #: the class that is used for response objects. See + #: :class:`~flask.Response` for more information. + response_class = Response #: path for the static files. If you don't want to use static files #: you can set this value to `None` in which case no URL rule is added @@ -266,7 +276,9 @@ class Flask(object): return run_simple(host, port, self, **options) def test_client(self): - """Creates a test client for this application""" + """Creates a test client for this application. For information + about unit testing head over to :ref:`testing`. + """ from werkzeug import Client return Client(self, self.response_class, use_cookies=True) @@ -356,7 +368,7 @@ class Flask(object): Variables parts in the route can be specified with angular brackets (``/user/``). By default a variable part - in the URL accepts any string without a slash however a differnt + in the URL accepts any string without a slash however a different converter can be specified as well by using ````. Variable parts are passed to the view function as keyword