我正在用户模型中注册数据,并且还希望像概要文件模型中的first_name和last_name那样同时保存配置文件数据。我们是否可以在信号中获取请求对象数据
所以,我用django信号来存储配置文件信息并将邮件发送给用户。
但我们无法获得信号文件中的FIRST_NAME和LAST_NAME:
#---------------------------- Create profile at the time of registration --------------------------#
def register_profile(sender, **kwargs):
if kwargs.get('created'):
user = kwargs.get('instance')
request = kwargs.get("request")
if user.id is not None and user._disable_signals is not True:
profile = Profile(user=user)
if user.status is not 1:
#------------------- Send the registration mail to user and it have confirmation link ----------#
salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
activation_key = hashlib.sha1(salt+user.email).hexdigest()
key_expires = datetime.datetime.today() + datetime.timedelta(2)
#print user
profile.activation_key = activation_key
profile.key_expires = key_expires
#--------------------- End -------------------------------------------------------------#
profile.save()
if user.status is not 1:
user = model_to_dict(user)
BaseSendMail.delay(user,type='account_confirmation',key = activation_key)
return
post_save.connect(register_profile, sender=User, dispatch_uid='register_profile')
#-------------------------- End ---------------------------------------------------------------------#
在上面的代码中,我无法得到FIRST_NAME并在registration.Also的发送时间,我想姓氏数据提及first_name和last_name字段属于配置文件模型。
你不应该在django中使用全局变量,并且导入不会实现你想要的东西ither。 –