Django Rest -重定向密码表单?

slmsl1lt  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(153)

我最近升级到Django 4.0,并升级了django-allauthdjango-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表单所在的位置,我不完全确定这是否是正确的方法。
下面是我的一些设置和URL。
任何帮助都很感激。
谢谢你,谢谢

settings.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'
}

字符串

url.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')),

]

7ivaypg9

7ivaypg91#

所以我想通了!
我的urls.py更新如下:

from dj_rest_auth.views import PasswordResetConfirmView

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

字符串
这个url现在指向django rest API中的django密码重置确认视图,这可以在后端重置密码。
谢谢你,谢谢

相关问题