Kurt Peek
Kurt Peek

Reputation: 57741

Django REST framework not picking up API endpoint

I'm trying to refactor an API to use the Django REST framework. I've changed my urls.py to the following (still in Django 1.11):

from django.conf.urls import url
from . import views
from rest_framework import routers, serializers, viewsets
from .serializers import SessionSerializer
from .viewsets import SessionViewSet

router = routers.DefaultRouter()
router.register(r'^api/v1\.0/feedback/$', SessionViewSet)


urlpatterns = [
    url(r'^$', views.index),
    url(r'^api/v1\.0/profile/$', views.get_profile),
    url(r'^api/v1\.0/update_profile/$', views.update_profile),
    url(r'^api/v1\.0/update_password/$', views.update_password),
    url(r'^api/v1\.0/sessions/$', views.get_session),
    url(r'^api/v1\.0/user/$', views.get_user),
    url(r'^api/v1\.0/sessions/send_schedule_request/$', views.send_schedule_request),
    url(r'^api/v1\.0/sessions/confirm_session_time/$', views.confirm_session_time),
    url(r'^api/v1\.0/password_reset/$', views.password_reset),
    url(r'^api/v1\.0/me/apn/$', views.save_apn),
    url(r'^api/v1\.0/confirm_activation_code$', views.confirm_activation_code),
    url(r'^api/v1\.0/update_user_via_activation_code$', views.update_user_via_activation_code),
    url(r'^api/v1\.0/questions/$', views.get_questions),
    url(r'^api/v1\.0/answers/$', views.save_answers),
    # url(r'^api/v1\.0/feedback/$', views.record_feedback),
    url(r'^session_types/$', views.session_types),
    url(r'^send_custom_notification/(?P<id>\d+)/$', views.send_custom_notification, name='send_custom_notification'),
    url(r'^admin/lucy_web/send_session_time_notifications/(?P<user_id>\d+)/(?P<session_id>\d+)/$', views.send_session_time_notifications, name='send_session_time_notifications'),

    url(r'^admin/lucy_web/app_activate/(?P<id>\d+)/$', views.app_activate, name='app_activate'),
    url(r'^admin/lucy_web/create_activation_code/(?P<id>\d+)/$', views.create_activation_code, name='create_activation_code'),
]

However, if I python manage.py runserver and go to localhost:8000/api/v1.0/feedback/, I get a 404 error response:

enter image description here

It seems like the r'^api/v1\.0/feedback/ endpoint is not being picked up, even though it is passed as an argument to router.register(). Any ideas why this is not working?

Upvotes: 1

Views: 2448

Answers (1)

Vignesh
Vignesh

Reputation: 512

You haven't added the default router urls back to the urlpatterns variable like this,

urlpatterns = [...]
urlpatterns += router.urls

Take a look at the usage section here

Upvotes: 3

Related Questions