I followed the simple quickstart tutorial in the official documentation of django rest framework.
https://www.django-rest-framework.org/tutorial/quickstart/
The tutorial works fine. The URL of the browsable API is at 127.0.0.1:8000
. How do I change it to 127.0.0.1:8000/api
?
The code for urls.py
;
from django.urls import include, path
from rest_framework import routers
from tutorial.quickstart import views
router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'groups', views.GroupViewSet)
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
path('', include(router.urls)),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
I am using django v4, python v3.9
CodePudding user response:
Just change the prefix via path()
, like you've done for api-auth/
.
(This is not DRF-specific; it's just the regular path()
function you use to mount views onto URLs.)
path('', include(router.urls)),
->
path('api/', include(router.urls)),