意外的密码字段

时间:2015-11-17 16:15:11

标签: django django-forms django-templates

我正在尝试在登录过程后创建第一页。我创建了一个表单,允许用户提供更详细的信息。

class AdditionalUserInfoForm(UserCreationForm):
    """
    Form for onboarding a new user account.

    """
    this_year = datetime.date.today().year
    Years = range(this_year-70, this_year+1)

    required_css_class = 'required'
    first_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'First Name'}), label="")
    middle_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Middle Name'}), label="")
    last_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Last Name'}), label="")
    date_of_birth = forms.DateField(widget=forms.extras.widgets.SelectDateWidget(years=Years))
    Primary_address = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Primary address'}), label="")
    Primary_address_zipcode = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Zip Code'}), label="")

    class Meta:
        model = User
        fields = ('first_name', 'middle_name', 'last_name', 'date_of_birth', 'Primary_address', 'Primary_address_zipcode')

您可以看到我没有任何密码输入。但是,当我渲染表单时,我得到了这个。此页面是否需要经过身份验证的用户?如果是这样,我如何让用户进行身份验证,特别是因为他们刚刚登录。

enter image description here

下面是我的html文件。

<form action="/summary/" method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Submit" />
</form>

这是html输出。电子邮件是用户的必填字段,但不是表单。

<p class="required"> <input id="id_Primary_address" name="Primary_address" placeholder="Primary address" type="text" /></p>
<p class="required"> <input id="id_Primary_address_zipcode" name="Primary_address_zipcode" placeholder="Zip Code" type="text" /></p>
<p class="required"><label class="required" for="id_password1">Password:</label> <input id="id_password1" name="password1" type="password" /></p>
<p class="required"><label class="required" for="id_password2">Password confirmation:</label> <input id="id_password2" name="password2" type="password" /> <span class="helptext">Enter the same password as above, for verification.</span></p>
<input type="submit" value="Submit" />

1 个答案:

答案 0 :(得分:0)

您已将UserCreationForm子类化,其中包含两个密码字段。如果您已经创建了用户,则应该改为forms.ModelForm