Flask-Classful

raw JSON →
0.16.0 verified Fri May 01 auth: no python

Flask-Classful provides class-based views for Flask, allowing you to define methods corresponding to HTTP methods (GET, POST, etc.) and automatically generate routes. Version 0.16.0 (latest) fixes compatibility with Flask >= 2.2. The library is now maintained under the Pallets Community Ecosystem. Release cadence is irregular.

pip install flask-classful
error AttributeError: module 'flask_classful' has no attribute 'FlaskView'
cause Incorrect import path; possibly installed a different package or misnamed.
fix
Use from flask_classful import FlaskView.
error ImportError: cannot import name 'FlaskView' from 'flask.ext.classy'
cause Trying to import from the old `flask.ext.classy` pattern, which is no longer supported.
fix
Use from flask_classful import FlaskView.
breaking Flask-Classful v0.16.0 requires Flask >= 2.2. Older versions of Flask may cause errors.
fix Upgrade Flask to >= 2.2.
deprecated The `inspect.getargspec` usage is deprecated; removed in Python 3.11+. Make sure you are using Flask-Classful v0.14.2 or later.
fix Upgrade to v0.14.2 or higher to avoid deprecation warnings.
gotcha Route methods are automatically derived from HTTP method names (e.g., `get`, `post`). Do not define a method named `route` or `register` as they conflict with the class internals.
fix Rename methods that conflict with FlaskView internals.

Minimal Flask app with a class-based view. Access http://localhost:5000/my-view/ to see 'Hello World!'.

from flask import Flask
from flask_classful import FlaskView

app = Flask(__name__)

class MyView(FlaskView):
    def index(self):
        return "Hello World!"

MyView.register(app)

if __name__ == "__main__":
    app.run()