我一直试图设置密码重置功能在DRF使用django-rest-auth。早些时候,我得到了错误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 = ResetPasswordFormsettings.py
REST_AUTH_SERIALIZERS = {
'PASSWORD_RESET_SERIALIZER': 'api.serializers.PasswordSerializer',
}但是,现在我要讨论另一个问题-- "NoReverseMatch: Reversefor‘account_reset_password_from_key’getting,'account_reset_password_from_key‘不是一个有效的视图函数或模式名。“。也没有找到任何解决办法或解决办法。
任何帮助都将不胜感激。
发布于 2017-12-22 08:37:32
所以,我终于让密码重置功能起作用了。是这样的-
我们只需要urls.py中的一个网址-
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配置首先会在/api/rest-auth/password/reset/错误时引发TemplateDoesNotExist。经过大量调试,我发现这个问题是针对驻留在Django Admin的模板目录下的模板- registration/password_reset_email.html提出的。这是因为我正在使用的另一个Django应用程序,它已经禁用django管理应用程序。
因此,在'django.contrib.admin'下添加INSTALLED_APPS并移除序列化器解决了这个问题。
我希望这也能为其他人解决问题。
PS:调试器是你最好的朋友。;)
https://stackoverflow.com/questions/47929991
复制相似问题