Add a decorator syntax for registering viewsets with routers #8917
-
I've always thought it would be good to allow a decorator style syntax for registering routes: Currently, I always have a list of viewset classes, and at the end of the file a list of registrations for those classes. Instead, something like this would be nice: @router.register('some-path')
class MyViewSet(viewsets.ViewSet):
... The only change required would be to make the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I created a quick PR implementing this: |
Beta Was this translation helpful? Give feedback.
-
the syntax looks small n good, but we have to reach a consensus from all the old maintainers of @encode/django-rest-framework as we are very careful introducing new API surface to the framework at this stage of projects life cycle. |
Beta Was this translation helpful? Give feedback.
-
To be honest i dont think adding decorator based routing is a good idea for this project. ( as it will add more churn to an already established library that is used by thousands of projects | Plus not everyone is a fan of this type of routing ) If you want decorator based routing maybe you can look into |
Beta Was this translation helpful? Give feedback.
I'm not a fan. Route resolution becomes dependent on import order.