[Fixed]-How do I call a Django Rest Framework URL using namespacing?

21👍

When registering views with the router, you can pass the base_name in as the third argument. This base name is used to generate the individual url names, which are generated as [base_name]-list and [base_name]-detail.

In your case, you are registering your viewset as

router.register(r'meetings', MeetingViewSet, 'meetings-list')

So the base_name is meetings-list, and the view names are meetings-list-list and meetings-list-detail. It sounds like you are looking for meetings-list and meetings-detail, which would require a base_name of meetings.

router.register(r'meetings', MeetingViewSet, 'meetings')

You are also using the now-deprecated patterns syntax for defining urls, but you are not actually using the right url calls that work with it. I would recommend just replacing the patterns and wrapping your list of urls with a standard Python list/tuple ([] or ()).

This should fix your issue, and the call to reverse should resolve for you.

3👍

I think this looks much better and cleaner for you:

router_urls = patterns(
    '',
    url(r'^meetings/$', MeetingViewSet.as_view(), 'meetings-list'),
)

urlpatterns = patterns(
    '',
    url(r'^(?P<pk>\d+)/', include(router_urls, namespace='router')),
)

Then, you wil do reverse('router:meetings-list', args=(pk, ))

I supposed that MeetingViewSet is a CBV

Leave a comment