我正在尝试在用户使用 django-templated-mail 注册帐户后发送验证电子邮件。这是我在创建用户后得到的错误: AttributeError 'dict' object has no attribute 'get_host'
所以 Django 试图调用 get_host() 并且无法调用?所以这是一个错误,因为它无法检索我的主机名?有人可以指出我在这里缺少什么吗?
class UserListView(generics.ListCreateAPIView):
serializer_class = UserSerializer
def perform_create(self, serializer):
user = serializer.save()
context = {'user': user}
to = user.email
email.ActivationEmail(context).send(to)
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'password', 'email')
extra_kwargs = {'password': {'write_only': True}}
def create(self, validated_data):
password = validated_data.pop('password')
user = super(UserSerializer, self).create(validated_data)
user.set_password(password)
user.save()
return user
class ActivationEmail(BaseEmailMessage):
template_name = 'email/activation.html'
def get_context_data(self):
context = super(ActivationEmail, self).get_context_data()
user = context.get('user')
context['uid'] = utils.encode_uid(user.pk)
context['token'] = default_token_generator.make_token(user)
context['url'] = 'verify/{uid}/{token}'.format(**context)
return context
饮歌长啸
慕哥6287543
相关分类