Class-based View Extension Point

Description

The extension point abbreviation is cvep.

Flask-Classful is an extension that adds class-based views to Flask.

This extension point is flask-classful based to extend routing, so your application needs to install it (document url is: flask_classful_docs):

$ pip install -U Flask-Classful

The plugin needs to return the cvep field via register. The returned cvep data type can be dict, list or tuple, em, the format is similar to vep.

The dict format is {view_class:, other register options}, see the flask_classful_register for more options, a common example is:

from flask_classful import FlaskView

class TestView(FlaskView):

    def index(self):
        return "test"

dict(view_class=TestView, route_base="/classful")

Other types are represented as multiple routes, and multiple dict data of the above type can be nested.

The Flask-PluginKit loads cvep via _cvep_handler(), this method will detect cvep rules and specific content.

Example

  • Plugin registration for cvep

from flask_classful import FlaskView

quotes = [
    "A noble spirit embiggens the smallest man! ~ Jebediah Springfield",
    "If there is a way to do it better... find it. ~ Thomas Edison",
    "No one knows what he can do till he tries. ~ Publilius Syrus"
]

class QuotesView(FlaskView):

    def index(self):
        """Visit: http://localhost:5000/quotes/"""
        return "<br>".join(quotes)

    def get(self, id):
        """Visit: http://localhost:5000/quotes/1/"""
        id = int(id)
        if id < len(quotes) - 1:
            return quotes[id]
        else:
            return "Not Found", 404

def register():
    return dict(
        cvep = [
            dict(view_class=QuotesView)
        ]
    )