Dispatches request methods to the corresponding instance methods. For example, if you implement a ``get`` method, it will be used to handle ``GET`` requests. This can be useful for defining a REST API. :attr:`methods` is automatically set based on the methods defined on the class. See :doc:`views` for a detailed guide. .. code-block:: python class CounterAPI(MethodView): def get(self): return str(session.get("counter", 0)) def post(self): session["counter"] = session.get("counter", 0) + 1 return redirect(url_for("counter")) app.add_url_rule( "/counter", view_func=CounterAPI.as_view("counter") )
Method | __init |
Undocumented |
Method | dispatch |
The actual view function behavior. Subclasses must override this and return a valid response. Any variables from the URL rule are passed as keyword arguments. |
Inherited from View
:
Class Method | as |
Convert the class into a view function that can be registered for a route. |
Class Variable | decorators |
Undocumented |
Class Variable | init |
Undocumented |
Class Variable | methods |
Undocumented |
Class Variable | provide |
Undocumented |
flask.views.View.dispatch_request
The actual view function behavior. Subclasses must override this and return a valid response. Any variables from the URL rule are passed as keyword arguments.