1

我想制作 2 个不同的文档。一种是公开的,只有很少的 api 方法,没有 authz。另一种是用于所有 api 方法的私人使用,并且仅供授权用户使用。

4

1 回答 1

0

我将我的路线分为公共和私人路线,并声明了 2 个模式。但我不知道如何按访问级别过滤方法,并且组件中有私有模型 =(

public_urlpatterns = [
....
    path("users/current/", CurrentUserView.as_view(), name="api_current_user"), 
....
]
public_urlpatterns += public_api_router.urls

public_urlpatterns += [
    path("schema/", SpectacularAPIView.as_view(urlconf=public_urlpatterns), name="schema"),
    path("redoc/", SpectacularRedocView.as_view(url_name="schema"), name="redoc"),
    path("swagger/", SpectacularSwaggerView.as_view(url_name="schema"), name="swagger-ui",),
]

all_urlpatterns = private_urlpatterns + public_urlpatterns + api_router.urls + public_api_router.urls

urlpatterns = [
    path("api/", include(all_urlpatterns)),
    path("api/schema_private/", login_required(SpectacularAPIView.as_view()), name="schema-private"),
    path(
        "api/swagger_private/",
        login_required(SpectacularSwaggerView.as_view(url_name="schema-private")),
        name="swagger-ui",
    ),
    path("api/redoc_private/", login_required(SpectacularRedocView.as_view(url_name="schema-private")), name="redoc"),
]
于 2021-12-03T09:48:41.990 回答