django-rest-auth:密码重置功能问题

django-rest-auth: Issue with Password Reset functionaliity

我一直在尝试使用 django-rest-auth 在 DRF 中设置密码重置功能。早些时候我收到错误 TemplateDoesNotExist:registration/password_reset_email.html 我通过添加以下代码解决了这个问题

serializer.py

from rest_auth.serializers import PasswordResetSerializer
from allauth.account.forms import ResetPasswordForm  

class PasswordSerializer(PasswordResetSerializer):
    password_reset_form_class = ResetPasswordForm

settings.py

REST_AUTH_SERIALIZERS = {
    'PASSWORD_RESET_SERIALIZER': 'api.serializers.PasswordSerializer',
}

但是,现在我要进入另一个问题 - "NoReverseMatch: Reverse for 'account_reset_password_from_key' not found. 'account_reset_password_from_key' is not a valid view function or pattern name."。并且还没有找到任何解决方案或解决方法。

如有任何帮助,我们将不胜感激。

所以,我终于可以使用密码重置功能了。这是怎么回事-

我们 urls.py -

中只需要一个 URL
urlpatterns = [
url(r'^account/', include('allauth.urls')),  
url(r'^rest-auth/', include('rest_auth.urls')),  

# This is the only URL required for BASIC password reset functionality.
# This URL creates the confirmation link which is sent via e-mail. All of the rest
# password reset features get their reverse lookup via django-allauth and django-rest-auth.
url(r'^password-reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', TemplateView.as_view(),  name='password_reset_confirm'), 

url(r'^rest-auth/registration/account-confirm-email/(?P<key>[-:\w]+)/$', allauthemailconfirmation,
    name="account_confirm_email"),
url(r'^rest-auth/registration/', include('rest_auth.registration.urls'), name='account_signup'),  
]

使用此 URL 配置首先引发 TemplateDoesNotExist at /api/rest-auth/password/reset/ 错误。经过大量调试后,我发现问题出现在模板 registration/password_reset_email.html 中在 Django Admin 的模板目录下。发生这种情况是因为我正在使用另一个 Django 应用程序,它禁用了 Django 管理应用程序。

因此,在 INSTALLED_APPS 下添加 'django.contrib.admin' 和删除序列化程序解决了问题。

我希望这也能解决其他人的问题。

PS: 调试器是您最好的朋友。 ;)