title: how to reverse the URL of a ViewSet's custom action in django restframework
body: <p>I have defined a custom action for a ViewSet</p>
  
  <pre><code>from rest_framework import viewsets
  
  class UserViewSet(viewsets.ModelViewSet):
      @action(methods=['get'], detail=False, permission_classes=[permissions.AllowAny]) 
      def gender(self, request):
          ....
  </code></pre>
  
  <p>And the viewset is registered to url in the conventional way</p>
  
  <pre><code>from django.conf.urls import url, include                                          
  
  from rest_framework import routers                                                 
  from api import views                                                              
  
  
  router = routers.DefaultRouter()                                                   
  router.register(r'users', views.UserViewSet, base_name='myuser')                   
  
  urlpatterns = [                                                                    
      url(r'^', include(router.urls)),                                               
  ]   
  </code></pre>
  
  <p>The URL <code>/api/users/gender/</code> works. But I don't know how to get it using <code>reverse</code> in unit test. (I can surely hard code this URL, but it'll be nice to get it from code) </p>
  
  <p>According to the <a href="https://docs.djangoproject.com/en/1.11/ref/urlresolvers/#reverse" rel="noreferrer">django documentation</a>, the following code should work</p>
  
  <pre><code>reverse('admin:app_list', kwargs={'app_label': 'auth'})
  # '/admin/auth/'
  </code></pre>
  
  <p>But I tried the following and they don't work</p>
  
  <pre><code>reverse('myuser-list', kwargs={'app_label':'gender'})
  # errors out
  reverse('myuser-list', args=('gender',))
  # '/api/users.gender'
  </code></pre>
  
  <p>In the <a href="http://www.django-rest-framework.org/api-guide/viewsets/#reversing-action-urls" rel="noreferrer">django-restframework documentation</a>, there is a function called <code>reverse_action</code>. However, my attempts didn't work</p>
  
  <pre><code>from api.views import UserViewSet
  a = UserViewSet()
  a.reverse_action('gender') # error out
  from django.http import HttpRequest
  req = HttpRequest()
  req.method = 'GET'
  a.reverse_action('gender', request=req)  # still error out
  </code></pre>
  
  <p>What is the proper way to reverse the URL of that action?</p>