Issue
In Django I have a class based view:
class ApiRoot(APIView):
def get(request, format=None):
return Response({
'users': reverse('user-list', request=request, format=format),
#'snippets': reverse('snippet-list', request=request, format=format)
})
and the following url patterns in urls.py
urlpatterns = format_suffix_patterns([
url(r'^$', views.ApiRoot.as_view(), name='api-root'),
url(r'^snippets/$', views.SnippetList.as_view(), name='snippet-list'),
url(r'^snippets/(?P<pk>[0-9]+)/$', views.SnippetDetail.as_view(), name='snippet-detail'),
url(r'^users/$', views.UserList.as_view(), name='user-list'),
url(r'^users/(?P<pk>[0-9]+)/$', views.UserDetail.as_view(), name='user-detail'),
])
urlpatterns += [
url(r'^api-auth/', include('rest_framework.urls',
namespace='rest_framework')),
I think I wired up things properly but I get the following error:
NoReverseMatch at /
Reverse for 'user-list' with arguments '()' and keyword arguments '{u'format': <rest_framework.request.Request object at 0x7f99998c4c50>}' not found. 2 pattern(s) tried: [u'users\\.(?P<format>[a-z0-9]+)/?$', 'users/$']
Any Idea why?
thanks
Solution
You should reverse the url as reverse('user-list')
. That should solve your issue.
Answered By - trinchet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.