首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >django-rest-auth:发出密码重置功能

django-rest-auth:发出密码重置功能
EN

Stack Overflow用户
提问于 2017-12-21 17:31:07
回答 1查看 2.5K关注 0票数 2

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

serializer.py

代码语言:javascript
复制
from rest_auth.serializers import PasswordResetSerializer
from allauth.account.forms import ResetPasswordForm  

class PasswordSerializer(PasswordResetSerializer):
    password_reset_form_class = ResetPasswordForm

settings.py

代码语言:javascript
复制
REST_AUTH_SERIALIZERS = {
    'PASSWORD_RESET_SERIALIZER': 'api.serializers.PasswordSerializer',
}

但是,现在我要讨论另一个问题-- "NoReverseMatch: Reversefor‘account_reset_password_from_key’getting,'account_reset_password_from_key‘不是一个有效的视图函数或模式名。“。也没有找到任何解决办法或解决办法。

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-22 08:37:32

所以,我终于让密码重置功能起作用了。是这样的-

我们只需要urls.py中的一个网址-

代码语言:javascript
复制
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:调试器是你最好的朋友。;)

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47929991

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档