title: Getting a "bound method" error with my login form
body: <p>So my register form works fine, it successfully creates a new user. However my login form cannot log a user in. So when I log in with username/password entered correctly, and <code>print(form.non_field_errors)</code> in my view, I get this error:</p>
  
  <pre><code>&lt;bound method BaseForm.non_field_errors of &lt;UserLoginForm bound=True, valid=False, fields=(username;password)&gt;&gt;
  </code></pre>
  
  <p>Can somebody tell me what this means? So the login form is invalid but not sure why. And when I <code>print(form.errors)</code> in the same view I get this error:</p>
  
  <pre><code>&lt;ul class="errorlist"&gt;&lt;li&gt;username&lt;ul class="errorlist"&gt;&lt;li&gt;A user with that username already exists.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
  </code></pre>
  
  <p>Also, keep in mind these register and login functions don't have a seperate url, they are all on on the homepage (accessible via javascript onclick, to prevent page refresh). Here's my code:</p>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>def boxes_view(request):
  
      ...
  
  
      form = UserRegistrationForm(request.POST or None)
  
      form_login = UserLoginForm(request.POST or None)
  
      if request.user.is_authenticated():
          print('LOGGED IN')
  
      context = {
          'form': form,
          'form_login': form_login
      }
  
      return render(request, 'polls.html', context)
  
  
  def register(request):
      form = UserRegistrationForm(request.POST or None)
      if form.is_valid():
          username = form.cleaned_data['username']
          password = form.cleaned_data['password']
          email = form.cleaned_data['email']
          user = User.objects.create_user(username=username, password=password, email=email)
          user.save()
          return redirect('/')
      else:
          print(form.errors)
          print(form.non_field_errors)
          form = UserRegistrationForm()
      return redirect('/')
  
  
  def user_login(request):
      form_login = UserLoginForm(request.POST or None)
      if form_login.is_valid():
          username = form_login.cleaned_data['username']
          password = form_login.cleaned_data['password']
          user = authenticate(username=username, password=password)
          login(request, user)
          return redirect('/')
      else:
          print(form_login.errors)
          print(form_login.non_field_errors)
          form_login = UserLoginForm()
      return redirect('/')
  </code></pre>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>class UserLoginForm(forms.ModelForm):
      username = forms.CharField(max_length=25)
      password = forms.CharField(widget=forms.PasswordInput)
  
      class Meta:
          model = User
  
          fields = [
              'username',
              'password',
          ]
  
  
  class UserRegistrationForm(forms.ModelForm):
      email = forms.EmailField()
      username = forms.CharField(max_length=25)
      password = forms.CharField(widget=forms.PasswordInput)
      confirm_password = forms.CharField(widget=forms.PasswordInput)
  
      class Meta:
          model = User
  
          fields = [
              'username',
              'email',
              'password',
              'confirm_password',
          ]
  
      def clean(self):
          email = self.cleaned_data.get('email')
  
          current_emails = User.objects.filter(email=email)
  
          if current_emails.exists():
              raise forms.ValidationError("That email is taken")
  </code></pre>
  
  <p><strong>base.html</strong> #parent of polls.html</p>
  
  <pre><code>&lt;form method="post" enctype="multipart/form-data" action="{% url 'user_login' %}"&gt;{% csrf_token %}
      &lt;div class="loginBox"&gt;
          {{ form_login.username|placeholder:"username" }}
          {{ form_login.password|placeholder:"password" }}
  
          &lt;input type="submit" value="login" style="margin-left: 10px"/&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  
  &lt;form method="post" enctype="multipart/form-data" action="{% url 'register' %}"&gt;{% csrf_token %}
      &lt;div class="registerBox"&gt;
          {{ form.username|placeholder:"username" }}
          {{ form.email|placeholder:"email" }}
          {{ form.password|placeholder:"password" }}
          {{ form.confirm_password|placeholder:"confirm password" }}
  
          &lt;input type="submit" value="register" /&gt;
  
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  
  <p>BV = views.boxes_view</p>
  
  <pre><code>urlpatterns = [
      url(r'^$', BV, name='news'),
      url(r'^admin/', admin.site.urls, name='admin'),
      url(r'^post/', include('post.urls')),
      url(r'^user_login/', views.user_login, name='user_login'),
      url(r'^logout/', logout_view, name='logout'),
      url(r'^register/', views.register, name='register'),
  
  ]
  </code></pre>