Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 将函数从多个转换为单个_Django_Django Registration - Fatal编程技术网

Django 将函数从多个转换为单个

Django 将函数从多个转换为单个,django,django-registration,Django,Django Registration,我有一个来自django registration的功能,它向给定的收件人重新发送激活电子邮件。我正在尝试将该功能从接受给定电子邮件的多个用户转换为每个电子邮件仅接受一个用户。但是,当我尝试更改它时,它抛出了一个AttributeError def resend_activation(self, email, site): # for multiple emails -- this works sent = False users = User.objects.all().f

我有一个来自django registration的功能,它向给定的收件人重新发送激活电子邮件。我正在尝试将该功能从接受给定电子邮件的多个用户转换为每个电子邮件仅接受一个用户。但是,当我尝试更改它时,它抛出了一个
AttributeError

def resend_activation(self, email, site):   # for multiple emails -- this works
    sent = False
    users = User.objects.all().filter(email=email)

    if users:
        for user in users:
            registration_profiles = self.all().filter(user=user)
            for registration_profile in registration_profiles:
                if not registration_profile.activation_key_expired():
                    registration_profile.send_activation_email(site)
                    sent = True
    return sent

def resend_activation(self, email, site):   # for single email -- this does not work
    sent = False                            
    user = User.objects.all().filter(email=email)

    if user:
        registration_profile = self.all().get(user=user)
        if not registration_profile.activation_key_expired():
            registration_profile.send_activation_email(site)
            sent = True
    return sent
后一个函数抛出一个
AttributeError
,但我不明白为什么没有
for
循环,该函数就不能“工作”。我这里有什么问题?谢谢。

试试:

def resend_activation(self, email, site):
    sent = False
    # Get the user you are looking for
    try:
        single_user = User.objects.get(email=email)
    except User.DoesNotExist:
        return false

    # Get all the profiles for that single user
    registration_profiles = self.all().filter(user=user)
        # Loop through, and send an email to each of the profiles belonging to that user
        for registration_profile in registration_profiles:
            if not registration_profile.activation_key_expired():
                registration_profile.send_activation_email(site)
                sent = True
    return sent
在原始版本中,User.object.filter(email=email)正在返回一个queryset,它是从数据库中从查询filter(email=email)返回的对象的集合。原始文件中的for循环在这些对象中循环,并发送相应的电子邮件。您正在尝试呼叫发送\uuu\p>请尝试:

def resend_activation(self, email, site):
    sent = False
    # Get the user you are looking for
    try:
        single_user = User.objects.get(email=email)
    except User.DoesNotExist:
        return false

    # Get all the profiles for that single user
    registration_profiles = self.all().filter(user=user)
        # Loop through, and send an email to each of the profiles belonging to that user
        for registration_profile in registration_profiles:
            if not registration_profile.activation_key_expired():
                registration_profile.send_activation_email(site)
                sent = True
    return sent
在原始版本中,User.object.filter(email=email)正在返回一个queryset,它是从数据库中从查询filter(email=email)返回的对象的集合。原始文件中的for循环在这些对象中循环,并发送相应的电子邮件。你想打电话给送信人_