Reputation: 109
Edit: there wasn't any mistake, this code works.
I am using django 1.4.5, My form is not displaying all the fields I want:
My code is the following:
class MyRegistrationForm(UserCreationForm):
email = forms.EmailField(required=True)
first_name = forms.CharField(max_length=30)
last_name = forms.CharField(max_length=30)
class Meta:
model = User
fields = ('username', 'email', 'first_name', 'last_name', 'password1', 'password2')
def save(self, commit=True):
user = super(MyRegistrationForm, self).save(commit=False)
user.email = self.cleaned_data['email']
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
if commit:
user.save()
return user
It's only displaying the username, email and passwords.
Upvotes: 1
Views: 2386
Reputation: 86
So I tested this quickly just by initializing the form and printing it out to the terminal I copied your form code exactly and called as follows.
myregform = MyRegistrationForm()
print myregform
This return the following response in terminal
<tr><th><label for="id_username">Username:</label></th><td><input id="id_username" maxlength="30" name="username" type="text" /><br /><span class="helptext">Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.</span></td></tr>
<tr><th><label for="id_email">Email:</label></th><td><input id="id_email" name="email" type="text" /></td></tr>
<tr><th><label for="id_first_name">First name:</label></th><td><input id="id_first_name" maxlength="30" name="first_name" type="text" /></td></tr>
<tr><th><label for="id_last_name">Last name:</label></th><td><input id="id_last_name" maxlength="30" name="last_name" type="text" /></td></tr>
<tr><th><label for="id_password1">Password:</label></th><td><input id="id_password1" name="password1" type="password" /></td></tr>
<tr><th><label for="id_password2">Password confirmation:</label></th><td><input id="id_password2" name="password2" type="password" /><br /><span class="helptext">Enter the same password as above, for verification.</span></td></tr>
As you can see the first_name and last_name is displaying so my best guess would be that it has something to do with your template processing code. Maybe if you could also post that here I can have a look.
Upvotes: 1