Django Rest - 重定向密码表单?

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

我最近升级到 Django 4.0 并升级了

django-allauth
以及
django-rest-auth

当用户填写

http://localhost:8000/api/dj-rest-auth/password/reset/
下的密码重置表单时,他们会在控制台中看到一个链接,该链接转到:
http://localhost:8000/users/reset/2n/bxggn2-05019c81f9d6dfda6a10b7cfec09e839/

提供的链接让我看到这个旧表格:

如何在控制台中获得此消息以指向

accounts/password/reset/key/1-set-password/

该表格如下所示:

这就是我的

allauth
表单所在的地方,我不确定这是否是正确的方法。

下面是我的一些设置和网址。

我们非常乐意提供任何帮助。

谢谢!

设置.py

INSTALLED_APPS = [
    # Local,
    'api.apps.ApiConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.humanize',
    'django.contrib.sessions',
    'django.contrib.messages',
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'users',

    # 3rd Party
    'rest_framework',
    'rest_framework.authtoken',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'dj_rest_auth',
    'dj_rest_auth.registration',
    'corsheaders',
    'drf_yasg',
]

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
]


REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAdminUser',
        'rest_framework.permissions.IsAuthenticated',
    ],
    'DEFAULT_AUTHENTICATION_CLASSES': [
       'rest_framework.authentication.SessionAuthentication',
       'rest_framework.authentication.TokenAuthentication', 
    ],
      'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}

urls.py

from django.urls import path, include
from allauth.account.views import ConfirmEmailView, EmailVerificationSentView 

urlpatterns = [
    path('accounts/', include('allauth.urls')),
    path('', include('users.urls')),

    path('api/', include('api.urls')),
    path('api-auth/', include('rest_framework.urls')),

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

    path('api/dj-rest-auth/', include('dj_rest_auth.urls')),
    path('api/dj-rest-auth/registration/', include('dj_rest_auth.registration.urls')),

    path('api/rest-auth/registration/account-confirm-email/', 
         EmailVerificationSentView.as_view(), name='account_email_verification_sent'),

    path('', include('django.contrib.auth.urls')),    
    path('users/', include('users.urls')),
    path('users/', include('django.contrib.auth.urls')),


]
python django django-rest-framework django-serializer django-allauth
1个回答
0
投票

所以我想通了!

必须将我的

urls.py
更新为以下内容:

from dj_rest_auth.views import PasswordResetConfirmView

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

此 url 现在指向 django Rest API 中的 django 密码重置确认视图,可以在后端重置密码。

谢谢!

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