Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.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
Python 在Django中创建用户时执行某些操作_Python_Django_Facebook_Python Social Auth_Receiver - Fatal编程技术网

Python 在Django中创建用户时执行某些操作

Python 在Django中创建用户时执行某些操作,python,django,facebook,python-social-auth,receiver,Python,Django,Facebook,Python Social Auth,Receiver,我正在使用social auth应用程序django与Facebook和Google进行社交身份验证。我试图在创建用户后创建一个接收器,以执行某些命令,例如在用户创建后显示教程(仅一次) 下面是我正在尝试做的事情,但还没有成功 from social_core.pipeline.user import create_user @receiver(create_user) def after_user_created(request, user, **kwargs): userprofi

我正在使用social auth应用程序django与Facebook和Google进行社交身份验证。我试图在创建用户后创建一个接收器,以执行某些命令,例如在用户创建后显示教程(仅一次)

下面是我正在尝试做的事情,但还没有成功

from social_core.pipeline.user import create_user

@receiver(create_user)
def after_user_created(request, user, **kwargs):
    userprofile = UserProfile.objects.create(user=user)
    userprofile.full_name = user.first_name + " " + user.last_name
    userprofile.save()
    request.session['first_login'] = True
    return render_to_response("main/highlights/highlights.html",locals(),RequestContext(request))

本质上,我如何创建某种接收器,以便在创建一个唯一的用户后激活,以便在创建该用户后执行自定义操作?我当前的代码似乎不起作用

在你的app models.py中编写一个预保存信号,如下所示:

@receiver(pre_save, sender=User)
def show_tutorial(sender, instance=None, **kwargs):
    # For first time creation of user display tutorial
    if instance._state.adding:
        # display tutorial() 

在app models.py中编写一个预保存信号,如下所示:

@receiver(pre_save, sender=User)
def show_tutorial(sender, instance=None, **kwargs):
    # For first time creation of user display tutorial
    if instance._state.adding:
        # display tutorial() 

我试着按照你说的做并发出请求。session['first_login']=True,你把#display tutorial()放在那里,但我得到了一个错误:缺少一个必需的位置参数:“request”我试着按照你说的做并发出请求。session['first_login'=True,你把#display tutorial()放在那里但我得到了这个错误:缺少1个必需的位置参数:“request”