Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Aha! The validation error message that you are seeing is actually not a validation error message. Let me explain. When you render the model form instance using <code>as_p</code>, it renders each field in the following way:</p> <pre><code>&lt;p&gt;&lt;label ...&gt;fieldname&lt;/label&gt; &lt;input ... name="fieldname" /&gt; HELP TEXT IF ANY&lt;/p&gt; </code></pre> <p>The string <code>Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters</code> that you are seeing to the right hand side of the field is nothing but the help text. This help text is taken from the model definition - you can verify this by visiting <code>django/contrib/auth/models.py</code> and inspecting the definition of <code>User</code> class.</p> <p>When you override the <code>username</code> field you are omitting any help text. Naturally the "error" disappears. </p> <p>In order to verify this theory do the following in your <code>main</code> method.</p> <pre><code>def main(request): uf = forms.UserForm() upf = forms.UserProfileForm() print "User form is bound:%s errors:%s" % (uf.is_bound, uf.errors) return render_to_response("authentication/index.html", {'form1': uf, 'form2':upf}) </code></pre> <p><strong>Update</strong></p> <pre><code>if self.cleaned_data['cpassword']!=self.cleaned_data['password']: </code></pre> <p>This line can cause trouble when the user doesn't supply one or both of <code>password</code> and <code>cpassword</code>. For example, try this from the Django shell:</p> <pre><code>&gt;&gt;&gt; data = dict(username = 'admin', cpassword = 'foo', email='admin@bar.com') &gt;&gt;&gt; f = RegisterForm(data) &gt;&gt;&gt; f.is_bound True &gt;&gt;&gt; f.is_valid() Traceback (most recent call last): ... File "&lt;pyshell#2&gt;", line 8, in clean if self.cleaned_data['cpassword']!=self.cleaned_data['password']: KeyError: 'password' </code></pre> <p>Change your form's <code>clean</code> method to make sure that both values are present before comparing. Something like this:</p> <pre><code>def clean(self): password = self.cleaned_data.get('password', None) cpassword = self.cleaned_data.get('cpassword', None) if password and cpassword and (password == cpassword): return self.cleaned_data else: raise forms.ValidationError("Passwords don't match") </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload