python - 如何从 Django 内置 API 文档中排除 rest-auth 端点?

标签 python django django-rest-framework swagger django-rest-auth

要在 Django 文档中隐藏端点,只需 @schema(None)例如必须添加到 GenericAPIView ,但是我对这两个网址有问题:

url(r'^rest-auth/', include('rest_auth.urls')),
url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),

我无法添加 @schema(None)装饰器,因为我没有为这些 url 声明 View 。任何想法如何解决它?

最佳答案

我想出的解决方案:

(vf, app_name, namespace) = include('rest_auth.urls')

vf.LoginView = schema(None)(vf.LoginView)
vf.LoginView = schema(None)(vf.LogoutView)
vf.LoginView = schema(None)(vf.PasswordChangeView)
vf.LoginView = schema(None)(vf.PasswordResetConfirmView)
vf.LoginView = schema(None)(vf.PasswordResetView)
vf.LoginView = schema(None)(vf.UserDetailsView)

(vf_registration, app_name_registration, namespace_registration) = include('rest_auth.registration.urls')

vf_registration.RegisterView = schema(None)(vf_registration.RegisterView)
vf_registration.TemplateView = schema(None)(vf_registration.TemplateView)
vf_registration.VerifyEmailView = schema(None)(vf_registration.VerifyEmailView)

urlpatterns = [

    url(r'^rest-auth/', (vf, app_name, namespace)),
    url(r'^rest-auth/registration/', (vf_registration, app_name_registration, namespace_registration)),
]

关于python - 如何从 Django 内置 API 文档中排除 rest-auth 端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61850763/

相关文章:

python - 元类的 __repr__ 类,而不是类

python - 如果 setUpClass 抛出异常,如何使 python 单元测试失败

python - Python中的负模式匹配正则表达式

python - 从 2 列表制作字典

Django Rest Framework 更新或如果不存在则创建

django - 我不明白 Django-Rest-Framework 序列化器是如何工作的

python - conda安装django时出现PermissionError(13, 'Permission denied')

python - Django admin - 覆盖已经注册的模型

django - Django Rest Framework 中的员工权限

django - 在我的 ViewSet 中使用 detail_route 时,在 DRF 序列化程序中收到 'request' 的 KeyError