这是我的测试代码,但它不起作用:
from django.conf.urls import url, include
from rest_framework import routers
from apps.apis import views
router = routers.DefaultRouter()
router.register(r'users1', views.UserViewSet)
router.register(r'hello', views.hello, base_name='hello')
urlpatterns = [
url(r'', include(router.urls)),
url(r'^hello$', views.hello ),
url(r'^api-auth/', include('rest_framework.urls',namespace='rest_framework')),
]
如何将@api_view注册到路由器,我可以在API根页面看到它?谢谢大家。
答案 0 :(得分:0)
你不能。
您的视图需要从ViewSet
继承才能显示在路由器中。
话虽如此,您只需添加APIView
ViewSet
转换为ViewSetMixin