我正在尝试在用户使用 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 userclass 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
2 回答
饮歌长啸
TA贡献1951条经验 获得超3个赞
ActivationEmail
将request
用作其初始值设定项的第一个位置参数。您将 thecontext
作为第一个位置参数传递,这会导致ActivationEmail
摔倒。
确保在创建request
实例时传递实例以及context
to ActivationEmail
。
email.ActivationEmail(self.request, context).send(to)
添加回答
举报
0/150
提交
取消