我正在尝试重构 API 以使用Django REST 框架。我已将其更改urls.py
为以下内容(仍在 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'),
]
但是,如果我python manage.py runserver
和 go to localhost:8000/api/v1.0/feedback/
,我会收到 404 错误响应:
似乎r'^api/v1\.0/feedback/
端点没有被拾取,即使它作为参数传递给router.register()
. 任何想法为什么这不起作用?