This my test code,but it is not work:
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')),
]
How to register an @api_view into router, and i can see it in API root page?Thanks all.
You can't.
Your view needs to inherit from ViewSet to appear in the routers.
This being said, you can simply turn an APIView into a ViewSet by adding the ViewSetMixin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With