【发布时间】:2019-08-13 16:06:25
【问题描述】:
我可能会误解一些东西。 django-rest-auth 提供RegisterView 并且应该在用户注册后将电子邮件发送到用户的电子邮件。但是,我注意到用户甚至在用户确认电子邮件之前就已注册is_active=True。那么,邮箱验证有什么用呢?当用户注册网站时,我是否必须覆盖某些内容并使用is_active=False 创建用户?如果是这样,我怎样才能正确地实现它?我遇到了麻烦。
这就是我所做的。
urls.py
path('api/v1/rest-auth/registration/', include('rest_auth.registration.urls')),
serializers.py
from rest_auth.registration.serializers import RegisterSerializer
class CustomRegistrationSerializer(RegisterSerializer):
def save(self, request):
user = super(CustomRegistrationSerializer, self).save(request)
user.is_active = False
return user
settings.py
REST_AUTH_REGISTER_SERIALIZERS = {
'REGISTER_SERIALIZER': 'appname.serializers.CustomRegistrationSerializer',
}
这是我遇到的一个错误。
文件“rest_auth/registration/views.py”,第 46 行,在调度中 return super(RegisterView, self).dispatch(*args, **kwargs)
文件“/rest_framework/views.py”,第 495 行,在调度中 响应 = self.handle_exception(exc)
文件“rest_framework/views.py”,第 455 行,在 handle_exception 中 self.raise_uncaught_exception(exc)
文件“rest_framework/views.py”,第 492 行,在调度中 response = handler(request, *args, **kwargs)
文件“rest_framework/generics.py”,第 192 行,在帖子中 return self.create(request, *args, **kwargs)
文件“rest_auth/registration/views.py”,第 65 行,在创建中 user = self.perform_create(serializer)
文件“rest_auth/registration/views.py”,第 81 行,在 perform_create 无)
文件“allauth/account/utils.py”,第 183 行,在 complete_signup 中 signal_kwargs=signal_kwargs)
文件“/allauth/account/utils.py”,第 133 行,在 perform_login 中 return adapter.respond_user_inactive(request, user)
文件“allauth/account/adapter.py”,第 454 行,在 respond_user_inactive 反向('account_inactive'))
文件“django/urls/resolvers.py”,第 622 行,在 _reverse_with_prefix 提高 NoReverseMatch(味精) django.urls.exceptions.NoReverseMatch:找不到“account_inactive”的反向。 “account_inactive”不是有效的视图函数或模式名称。
我想听听使用django-rest-auth 的人如何处理注册。
有人用过django-rest-auth 并且可以给我提示吗?
【问题讨论】:
标签: django django-rest-framework django-rest-auth