Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.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 allauth时如何自定义用户配置文件选择_Django_Django Models_Django Views_Django Allauth - Fatal编程技术网

使用django allauth时如何自定义用户配置文件选择

使用django allauth时如何自定义用户配置文件选择,django,django-models,django-views,django-allauth,Django,Django Models,Django Views,Django Allauth,我正在尝试创建一个表单类,该类仅在注册时要求用户为我的自定义用户模型提供附加数据 我的意图是在注册后只要求用户添加两个字段。我相信我每次都会问。我试过下面的方法,但不起作用 目前在myaap/forms.py中,我有: class SetUniversityForm(forms.ModelForm): program = forms.CharField( required=False, widget=forms.TextInput(

我正在尝试创建一个表单类,该类仅在注册时要求用户为我的自定义用户模型提供附加数据

我的意图是在注册后只要求用户添加两个字段。我相信我每次都会问。我试过下面的方法,但不起作用

目前在my
aap/forms.py中,我有:

class SetUniversityForm(forms.ModelForm):
    
    program = forms.CharField(
        required=False,
        widget=forms.TextInput(
            attrs={
                "placeholder":"What are you studying?",
                "class": "form-control",
            }
        )
    )
    
    university = forms.ChoiceField(
        label='',
        required=True,
        choices = UNIVERSITY_CHOICES,

        widget=MySelect(
        attrs={
            "class":"form-control",
            
        }
        ), 
    )
    
    class Meta:
        model = Profile
        fields = ('university','program')
    
    def signup(self, request, user):
        user.university = self.cleaned_data['university']
        user.program = self.cleaned_data['program']
        user.save()
默认用户模型为:

class Profile(AbstractUser):
    bio = models.TextField()
    university = models.CharField(max_length=50)
    program = models.CharField(blank=True,max_length=100)
在my
settings.py
中,我有:

class SetUniversityForm(forms.ModelForm):
    
    program = forms.CharField(
        required=False,
        widget=forms.TextInput(
            attrs={
                "placeholder":"What are you studying?",
                "class": "form-control",
            }
        )
    )
    
    university = forms.ChoiceField(
        label='',
        required=True,
        choices = UNIVERSITY_CHOICES,

        widget=MySelect(
        attrs={
            "class":"form-control",
            
        }
        ), 
    )
    
    class Meta:
        model = Profile
        fields = ('university','program')
    
    def signup(self, request, user):
        user.university = self.cleaned_data['university']
        user.program = self.cleaned_data['program']
        user.save()
帐户\注册\表单\类='app.forms.SetUniversityForm'

然而,当用户第一次使用Google注册时,它仍然会重定向到我的
登录\u重定向\u URL
。我如何实现这一点?我看过:

但我无法修复它。我也尝试过使用适配器。但我只需要这些注册信息