Open
Description
I was just implementing a project and read up on the documentation about specifying base views. While this works, it seems a little clunky and prone to errors. I was wondering if the project would be open to inferring the routes from the class' __dict__
?
Something akin to this (could be cleaned up a little, but as an example works fine:
# foo.py
from flask_classful import FlaskView
class FooView(FlaskView):
def get(self, id):
pass # etc
# somewhere_else.py
def routes(view):
routes = []
for k, v in view.__dict__.items():
if callable(v) and not k.startswith('_'):
routes.append(k)
return routes
The above example would return ['get']
, avoids gathering any methods defined on parent classes, and works for larger inheritance chains AFAICT.
(I added the bit obviously about not starting with _
, but it seems like a reasonable addition?)
Metadata
Metadata
Assignees
Labels
No labels
Activity