1

Below is my django routing configuration:

# main module
urlpatterns = patterns('',
    url(r'^api/', include('api.urls')),
)

# api module
urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
    url(r'^users/(?P<id>\d+)/?$', views.users, name='users')
)

I can access specific users (using ids) with http://localhost:8000/api/users/1/ but I can't access list of users: http://localhost:8000/api/users/:

Using the URLconf defined in duck_rip.urls, Django tried these URL patterns, in this order:
^api/ ^$ [name='index']
^api/ ^users/(?P<id>\d+) [name='users']
The current URL, api/users/, didn't match any of these.

Before this, I had my module urls like this:

url(r'^users/$', views.users, name='users')

and I had access to http://localhost:8000/api/users/. Can someone please explain me what is the error I make?

2
  • The error is straight forward none of the url patterns is handling ^users/$. Commented Aug 5, 2013 at 16:41
  • @AshwiniChaudhary what should I change to make id parameter optional? Commented Aug 5, 2013 at 16:45

1 Answer 1

4

Just make id optional as:

url(r'^users/(?:(?P<id>\d+)/)?$', views.users, name='users')

And in view:

def users(request, id=None)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.