I have in my project in the main urls.py file the following:
# REST Framework packages
from rest_framework import routers
router = routers.DefaultRouter()
# ... My viewsets serialized
router.register(r'users', UserViewSet)
# ... Another viewsets
urlpatterns = [
url(r'^$', HomeView.as_view(), name='home'),
# Home url in my project
url(r'^', include('userprofiles.urls')),
# Call the userprofiles/urls.py application
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'))
# Rest frameworks urls
]
Until here, when I type in my browser calling to my local server http://localhost:8000/api/ I get this like response:
[08/Dec/2016 16:39:42] "GET /api/ HTTP/1.1" 200 7084
And my REST url's serialized models appear
After, I've created one url additional in the userprofiles/urls.py application with some regular expression of this way:
from .views import PatientDetail
urlpatterns = [
url(r'^(?P<slug>[\w\-]+)/$', PatientDetail.as_view(), name='patient_detail'),
]
And, when I go to http://localhost:8000/api/ I get this response:
Not Found: /api/
[08/Dec/2016 16:42:26] "GET /api/ HTTP/1.1" 404 1753
My rest frameworks url is not found and in my browser, denote that the url which call to PatientDetailView is the origin of this problem:
My PatientDetailView have the following:
class PatientDetail(LoginRequiredMixin, DetailView):
model = PatientProfile
template_name = 'patient_detail.html'
context_object_name = 'patientdetail'
def get_context_data(self, **kwargs):
context=super(PatientDetail, self).get_context_data(**kwargs)
# And other actions and validations here in forward ...
In my regular expressions defined in userprofiles/urls.py I am doing:
url(r'^(?P<slug>[\w\-]+)/$', PatientDetail.as_view(), name='patient_detail')
The model PatientProfile have a slug field (username of patient). I pass this slug in the url.
In addition I want that allow me alphanumerics characters upper and lowercase with the [\w\-] parameter, and allow underscores and hyphen characters and many times.
Is possible that my regular expression may be the origin of the problem?
What can be happened in relation to my /api django-restframework url be not found?
