Adding more views to a Router or viewset (Django-Rest-Framework)

后端 未结 4 545
既然无缘
既然无缘 2021-02-05 04:48

Essentially, I\'m trying to find a good way to attach more views to a Router without creating a custom Router. What\'s a good way to accomplish this?

He

4条回答
  •  梦毁少年i
    2021-02-05 05:07

    From Routing to extra methods on a ViewSet:

    I think you may need to route the method by hand, i.e. The Old-Fashioned Way™.

    First pull the method out as a separate view:

       set_password_view = UserViewSet.as_view({'post': 'set_password'})
    

    (or such)

    Then assign your URL:

       url(r'^users/username_available/$', set_password_view, name-=...)
    

    (Or such)

    There's a related question on SO.

提交回复
热议问题