django request.POST data is empty but works with other similar form
<p>I'm new to django and I was following a tutorial from django on how to process POST form data with a model</p>

<p><a href="https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view" rel="nofollow">https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view</a></p>

<p>I was able to do that for a simple login, and I can print out the variables in the console. The form.is_valid() function is true and works as expected for the login view.</p>

<p>I did the same exact thing for a registration page and I'm getting FALSE returned from the is_valid() function. I was tinkering with csrf tokens and that didn't seem to be causing the issue and thats why I didn't require them.</p>

<p>I think it's going to be a silly problem because I'm able to get the request.POST in the login case but not the registration. Any help is appreciated.</p>

<p>Here is my html form</p>

<pre><code> &lt;div id="login" class="animate form"&gt;
                        &lt;form  action="/signin" autocomplete="on" method ="POST"&gt; 
                            &lt;!--{% csrf_token} --&gt;
                            &lt;h1&gt;Log in&lt;/h1&gt; 
                            &lt;p&gt; 
                                &lt;label for="username" class="uname" data-icon="u" &gt; Your email or username &lt;/label&gt;
                                &lt;input id="username" name="username" required="required" type="text" placeholder="myusername or mymail@mail.com"/&gt;
                            &lt;/p&gt;
                            &lt;p&gt; 
                                &lt;label for="password" class="youpasswd" data-icon="p"&gt; Your password &lt;/label&gt;
                                &lt;input id="password" name="password" required="required" type="password" placeholder="eg. X8df!90EO" /&gt; 
                            &lt;/p&gt;
                            &lt;p class="keeplogin"&gt; 
              &lt;input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" /&gt; 
              &lt;label for="loginkeeping"&gt;Keep me logged in&lt;/label&gt;
            &lt;/p&gt;
                            &lt;p class="login button"&gt; 
                                &lt;input type="submit" value="Login" /&gt; 

&lt;div id="register" class="animate form"&gt;
                        &lt;form  action="/register" autocomplete="on" method ="POST"&gt; 
                            &lt;!--{% csrf_token %} --&gt;
                            &lt;h1&gt; Sign up &lt;/h1&gt; 
                            &lt;p&gt; 
                                &lt;label for="usernamesignup" class="uname" data-icon="u"&gt;Your username&lt;/label&gt;
                                &lt;input id="usernamesignup" name="usernamesignup" required="required" type="text" placeholder="mysuperusername690" /&gt;
                            &lt;/p&gt;
                            &lt;p&gt; 
                                &lt;label for="emailsignup" class="youmail" data-icon="e" &gt; Your email&lt;/label&gt;
                                &lt;input id="emailsignup" name="emailsignup" required="required" type="email" placeholder="mysupermail@mail.com"/&gt; 
                            &lt;/p&gt;
                            &lt;p&gt; 
                                &lt;label for="passwordsignup" class="youpasswd" data-icon="p"&gt;Your password &lt;/label&gt;
                                &lt;input id="passwordsignup" name="passwordsignup" required="required" type="password" placeholder="eg. X8df!90EO"/&gt;
                            &lt;/p&gt;
                            &lt;p&gt; 
                                &lt;label for="passwordsignup_confirm" class="youpasswd" data-icon="p"&gt;Please confirm your password &lt;/label&gt;
                                &lt;input id="passwordsignup_confirm" name="passwordsignup_confirm" required="required" type="password" placeholder="eg. X8df!90EO"/&gt;
                            &lt;/p&gt;
                            &lt;p class="signin button"&gt; 
              &lt;input type="submit" value="Sign up"/&gt;
</code></pre>

<p>Here is the forms.py</p>

<pre><code>from django import forms
from django.forms import CharField

class NameForm(forms.Form):
    username = forms.CharField(label = 'username', max_length=25)
    password = forms.CharField(label = 'password', max_length=25)


class RegForm(forms.Form):
    regName = forms.CharField(label = 'usernamesignup', max_length = 25)
    regEmail = forms.CharField(label = 'emailsignup', max_length = 50)
    regPassword = forms.CharField(label = 'passwordsignup', max_length = 30)
    regPasswordConfirm = forms.CharField(label = 'passwordsignup_confirm', max_length = 30)
</code></pre>

<p>Here is the views.py that's handling login/registration (this is rough draft)</p>

<pre><code>@csrf_exempt
def signin(request):
    #if this is a POST request we need to process the login credentials
    if request.method == 'POST':
        #create the form instance and populate with username/password
        form = NameForm(request.POST)
        #verify 
        print form
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            print username
            print password
            return render(request, 'webServer/home.html')
        else:
            return render(request, 'webServer/login.html')
    else:
        return render(request, 'webServer/login.html')

@csrf_exempt
def register(request):
    if request.method == 'POST':
        #create form instance and grab register credentials
        form2 = RegForm(request.POST)
        #verify not a duplicate entry (email, username)
        print form2
        if form2.is_valid():
            username = form2.cleaned_data['regPassword']
            return render(request, 'webServer/home.html')
        else:
            print 'had error'
            return render_to_response('webServer/errors.html',  {'form': form2})
    else:
        return render(request, 'webServer/login.html')
</code></pre>

<p>You seem to be using completely different field names in the template from the form - your form has <code>regName</code>, <code>regEmail</code> etc, but your template has <code>usernamesignup</code> etc.</p>

<p>In any case, you should be using the form object itself to output the fields:</p>

<pre><code>{{ form.regName.label_tag }}
{{ form.regName }}
{{ form.regName.errors }}
</code></pre>

python html django forms post