Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pallets-eco/flask-classful
Class based views for Flask
https://github.com/pallets-eco/flask-classful
flask python
Last synced: 1 day ago
JSON representation
Class based views for Flask
- Host: GitHub
- URL: https://github.com/pallets-eco/flask-classful
- Owner: pallets-eco
- License: bsd-3-clause
- Created: 2015-08-07T08:30:10.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-09-01T15:59:36.000Z (2 months ago)
- Last Synced: 2024-11-12T11:54:12.374Z (2 days ago)
- Topics: flask, python
- Language: Python
- Homepage: https://flask-classful.readthedocs.io
- Size: 968 KB
- Stars: 234
- Watchers: 21
- Forks: 55
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE.md
Awesome Lists containing this project
README
Flask-Classful
==============Flask-Classful is an extension that adds class-based views to [Flask][].
Class-based views are a way to encapsulate specific context and behavior for
routes and methods, complementing Flask's blueprints. They provide a more
powerful system than Flask's own `MethodView`.Read the documentation at .
[Flask]: https://flask.palletsprojects.com
Pallets Community Ecosystem
---------------------------> [!IMPORTANT]\
> This project is part of the Pallets Community Ecosystem. Pallets is the
> organization that maintains Flask; Pallets-Eco enables community maintenance
> of Flask extensions. If you are interested in helping maintain this project,
> please reach out on [the Pallets Discord server](https://discord.gg/pallets).A Basic Example
---------------This example defines a few routes by defining methods on a subclass of
`flask_classful.FlaskView`.```python
# example.py
import random
from flask import Flask, abort
from flask_classful import FlaskViewquotes = [
"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"
]app = Flask(__name__)
class QuotesView(FlaskView):
def index(self):
return "
".join(quotes)def get(self, id):
id = int(id)if id < len(quotes):
return quotes[id]abort(404)
def random(self):
return random.choice(quotes)QuotesView.register(app)
``````
$ flask -A example run --debug
```- http://127.0.0.1:5000/quotes/ shows all the quotes.
- http://127.0.0.1:5000/quotes/1/ shows a single quote.
- http://127.0.0.1:5000/quotes/random/ shows a random quote.Forked from Flask-Classy
------------------------> [!NOTE]\
> This is a fork of Flask-Classy to continue development after it was not
> updated for a long time.