【问题标题】:Remove user endpoints in Django rest auth在 Django rest auth 中删除用户端点
【发布时间】:2018-05-11 10:28:31
【问题描述】:

我正在使用 Django rest auth 进行用户帐户处理。为了更新用户信息,我创建了自定义端点,所以我不需要 djnago-rest-auth 生成的端点 /rest-auth/user/ (GET, PUT, PATCH)。如何删除这些端点?

urls.py

urlpatterns = [
    path('', include("rest_auth.urls"), name="user-auth"),
    path('register', include('rest_auth.registration.urls'), name="user-auth-registration"),
    path('<uid>/', views.UserProfileView.as_view(), name="user-profile"),
]

编辑

我想使用所有其他的 rest-auth url,如登录、注册等。但我只是不想要 /rest-auth/user/ 描述的 here

【问题讨论】:

  • 提供你的 urls.py
  • @SardorbekImomaliev 添加了

标签: django django-rest-framework django-rest-auth


【解决方案1】:

@bodoubleu 的回答无效,所以我手动添加了它们。

from rest_auth.views import (
    LoginView, LogoutView, PasswordChangeView,
    PasswordResetView, PasswordResetConfirmView
)

urlpatterns = [
    path('register', include('rest_auth.registration.urls'), name="user-auth-registration"),
    path('login', LoginView.as_view(), name="user-login"),
    path('logout', LogoutView.as_view(), name='user-logout'),
    path('password/change/', PasswordChangeView.as_view(), name='rest_password_change'),
    path('password/reset', PasswordResetView.as_view(), name='rest_password_reset'),
    path('password/reset/confirm/', PasswordResetConfirmView.as_view(), name='rest_password_reset_confirm'),
    path('<uid>/', views.UserProfileView.as_view(), name="user-profile"),
]

【讨论】:

  • 请问您如何查看带有 id 的用户个人资料。你使用的是令牌还是会话?非常感谢您的回复
  • @King 我正在使用令牌身份验证。关于查看用户资料,我认为它与这个问题无关。请再问一个问题,我会在那里回答。
【解决方案2】:

未经测试,但这应该可以。

urlpatterns = [
    path('user/', django.views.defaults.page_not_found),
    path('', include("rest_auth.urls"), name="user-auth"),
    path('register', include('rest_auth.registration.urls'), name="user-auth-registration"),
    path('<uid>/', views.UserProfileView.as_view(), name="user-profile"),
]

如果没有,您可以在您的 url 模式中手动定义所有 rest_auth.urls

【讨论】:

    猜你喜欢
    • 2021-08-18
    • 2020-09-03
    • 2020-10-03
    • 1970-01-01
    • 1970-01-01
    • 2018-06-14
    • 2017-03-14
    • 2015-08-31
    • 2016-07-14
    相关资源
    最近更新 更多