Theodore Howell
Theodore Howell

Reputation: 428

DRF Router issue with namespace

I am having a hell of a time getting the reverse function to work with my DRF implementation. Here is my urls.py, which i would assume the following reverse to work for:

urls.py

from django.conf.urls import url, include
from rest_framework import routers
from . import views
router = routers.DefaultRouter()
router.register(r'compressors', views.CompressorViewSet, base_name='compressors')
from django.urls import include, path
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
    url(r'^', include(router.urls, namespace='router')),
    url(r'^api-auth/', include('rest_framework.urls', 
namespace='rest_framework'))
]

And then

reverse('router:compressors', kwargs)

What am I missing? I am getting a app_name not provided, which when added to this file does not help. Is there a way for me to put an app_name to the router?

Upvotes: 1

Views: 403

Answers (1)

Theodore Howell
Theodore Howell

Reputation: 428

Turns out its just hard to find exactly how the use basename, I did not append '-list' to my reverse. It should have been the following, hope this helps others:

reverse('router:compressors-list')

Upvotes: 2

Related Questions