-
Notifications
You must be signed in to change notification settings - Fork 0
6. URLs
Carlos Aguilar edited this page May 16, 2018
·
1 revision
/testapi/urls.py
router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'groups', views.GroupViewSet)
router.register(r'points', views.PointViewSet)
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^api/auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^api/token/', token_views.obtain_auth_token),
url(r'^api/docs/', include_docs_urls(title='Test API', public=False)),
url(r'^api/', include(router.urls)),
]Using the DefaultRouter class, we register the ViewSets to various URL paths. This class will automatically parse the API and register any provided endpoint to its default URL.
In addition, we link those views, including the ones processed by our router to a bunch of URL paths:
-
api/: contains the API endpoints processed by our router class. -
api/auth/: contains a login form to enableSessionAuthenticationtesting within the API views. -
api/token/: this is a special API endpoint used to obtain a user authentication token in order to be able to use the API withTokenAuthentication. More on this matter later. -
api/docs/: contains autogenerated API endpoints documentation.