Django - 从 Django REST API 文档中排除 URL?使用 drf-yasg

问题描述 投票:0回答:1

如何使用当前代码从 API 文档中删除以下路径?

path('users/reset/<uidb64>/<token>/', PasswordResetConfirmView.as_view()),

我不希望生成此路径,因为它不是我的 API 的一部分。

我正在使用 drf_yasg 生成 re-doc 和 swagger 文档。

我当前看到的屏幕截图:

以下是

urls.py
的一些内容。

非常感谢任何帮助!

谢谢!

urls.py

from rest_framework.documentation import include_docs_urls
from rest_framework.schemas import get_schema_view
from rest_framework import permissions

from allauth.account.views import ConfirmEmailView, EmailVerificationSentView
from dj_rest_auth.views import PasswordResetConfirmView

from drf_yasg import openapi
from drf_yasg.views import get_schema_view

API_TITLE = ‘Test API
API_DESCRIPTION = ‘Test ‘Description

schema_view = get_schema_view(
   openapi.Info(
      title=“title-test”,
      default_version='v1',
      description=“blah blah.”,
   ),
   public=True,
   permission_classes=(permissions.IsAuthenticated,),
)

urlpatterns = [

    # AllAuth Authentication
    path('accounts/', include('allauth.urls')),


    # Django REST API Paths
    path('api/', include('api.urls')),
    path('api-auth/', include('rest_framework.urls')),

    # ConfirmEmailView Needs to be defined before the registration path
    path('api/dj-rest-auth/registration/account-confirm-email/<str:key>/',
         ConfirmEmailView.as_view()), 

    path('api/dj-rest-auth/', include('dj_rest_auth.urls')),
    path('api/dj-rest-auth/registration/', include('dj_rest_auth.registration.urls')),
    path('api/dj-rest-auth/registration/account-confirm-email/',
         EmailVerificationSentView.as_view(), name='account_email_verification_sent'),
    # path('api/dj-rest-auth/reset/<uidb64>/<token>/', PasswordResetConfirmView.as_view()),

    # API Documentation Paths
    path('docs/', include_docs_urls(title="GameStation API", description=API_DESCRIPTION)),
    # path('schema/', schema_view),
    path('swagger<format>/', schema_view.without_ui(cache_timeout=0), name='schema-json'),
    path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
    path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),

   ## This path is what I’m trying to remove
    path('users/reset/<uidb64>/<token>/', PasswordResetConfirmView.as_view()),

]
django django-rest-framework django-rest-auth drf-yasg django-swagger
1个回答
0
投票

所以不要排除:

path('users/reset/<uidb64>/<token>/', PasswordResetConfirmView.as_view()),

我把它完全删除了。删除该网址后,我的文档相应地显示为:

另外,我的后端看起来像这样:

这工作正常,因为我现在使用 allauth 进行注册/身份验证,并且这仅适用于 django 后端 API 内容。

如果我需要开发人员使用 ID 确认令牌,我可以向他们指出:

api/dj-rest-auth/password/reset/confirm/

希望这对人们有帮助。谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.