From 42b756411a2e0358adef44736b946fb1e31e9f5e Mon Sep 17 00:00:00 2001 From: Ollie Rutherfurd Date: Tue, 5 Oct 2010 15:28:48 -0400 Subject: [PATCH] support classes in addition to functions for views --- docs/_themes | 1 - flask/app.py | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) delete mode 160000 docs/_themes diff --git a/docs/_themes b/docs/_themes deleted file mode 160000 index 3d964b66..00000000 --- a/docs/_themes +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3d964b660442e23faedf801caed6e3c7bd42d5c9 diff --git a/flask/app.py b/flask/app.py index dbb64646..a9de47ba 100644 --- a/flask/app.py +++ b/flask/app.py @@ -507,8 +507,8 @@ class Flask(_PackageBoundObject): :param endpoint: the endpoint for the registered URL rule. Flask itself assumes the name of the view function as endpoint - :param view_func: the function to call when serving a request to the - provided endpoint + :param view_func: the function, or class, to call when serving a request to the + provided endpoint. :param options: the options to be forwarded to the underlying :class:`~werkzeug.routing.Rule` object. A change to Werkzeug is handling of method options. methods @@ -708,7 +708,10 @@ class Flask(_PackageBoundObject): if rule.provide_automatic_options and req.method == 'OPTIONS': return self.make_default_options_response() # otherwise dispatch to the handler for that endpoint - return self.view_functions[rule.endpoint](**req.view_args) + view_function = self.view_functions[rule.endpoint] + if isinstance(view_function, type): + view_function = view_function() + return view_function(**req.view_args) except HTTPException, e: return self.handle_http_exception(e)