[Answered ]-Django Rest Framework – main url HTTP/1.1" 404 Not Found

1👍

api is full match for regular expression [\w\-]+ using in ‘userprofiles.urls’. So when you type http://localhost:8000/api/ Django returns first found urlpattern which is url(r'^', include('userprofiles.urls')). Try to swap lines:

url(r'^pacientes/',  include('userprofiles.urls', namespace='pacientes')),
# Patients url
url(r'^api/', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
url(r'^', include('userprofiles.urls')),

1👍

The order in which you define your URLs matter. Django tries to match your URL against every pattern until one of them matches.

Note that you included this line:

url(r'^', include('userprofiles.urls')),

before:

url(r'^api/', include(router.urls)),

which wasn’t a problem because the first pattern to match was the latter.

However, when you added the PatientDetail view URL pattern:

url(r'^(?P<slug>[\w\-]+)/$', PatientDetail.as_view(), name='patient_detail')

/api/ was a match. Thus, the PatientDetail view was called and your 404 error happened because no patient was found with username api, not because the URL was not found.

Leave a comment