DRF:在基础 url 路由路径上禁用 GET 请求
DRF: Disable GET request on the base url route path
这是我在基础 urls.py,
中的 urlpatterns
urlpatterns = [
path('api/', include((router.urls, 'api'), namespace='api')),
]
当我浏览到 localhost:8000/api/
时,它公开了我所有的路线,
{
"accounts": "http://localhost:8000/api/accounts/",
"cases":"http://localhost:8000/api/cases/",
"issues": "http://localhost:8000/api/issues/"
}
有什么方法可以在 Django 应用程序级别禁用此公开吗?
您应该使用 SimpleRouter
而不是 DefaultRouter
。后者将视图添加到前者提供的路由中。
这是我在基础 urls.py,
中的 urlpatternsurlpatterns = [
path('api/', include((router.urls, 'api'), namespace='api')),
]
当我浏览到 localhost:8000/api/
时,它公开了我所有的路线,
{
"accounts": "http://localhost:8000/api/accounts/",
"cases":"http://localhost:8000/api/cases/",
"issues": "http://localhost:8000/api/issues/"
}
有什么方法可以在 Django 应用程序级别禁用此公开吗?
您应该使用 SimpleRouter
而不是 DefaultRouter
。后者将视图添加到前者提供的路由中。