title: Undefined path shows when trying to log in via email or username in Django
body: <p>I am making a login page with Django to log in via either username or email.
  I start a app users, in this app, I have customized the users/model.py</p>
  
  <pre><code>class UserProfile(AbstractUser):
      pass
  </code></pre>
  
  <p>in my users/views.py, I have code to read input name="username"</p>
  
  <pre><code>from .models import UserProfile
  from django.contrib.auth import authenticate
  from django.contrib.auth import login as auth_login
  from django.contrib.auth.backends import ModelBackend
  from django.db.models import Q
  class CustomBackend(ModelBackend):
      def authenticate(self, request, username=None, password=None, **kwargs):
          try:
              user = UserProfile.objects.get(Q(username=username)) | Q(email=username))
              if user.check_password(password):
                  return user
          except Exception as e:
              return None
  def login(request):
      if request.method == "POST":
          user_name = request.POST.get('username', '')
          password = request.POST.get('password', '')
          user = authenticate(username=user_name, password=password)
          if user is not None:
              auth_login(request,user)
              return render(request, 'index.html')
          else:
              return render(request, 'login.html',{})
  
      elif request.method == 'GET':
          return render(request,"login.html",{})
  </code></pre>
  
  <p>my templates/login.html</p>
  
  <pre><code>&lt;form action="/login/" method="post" id="jsLoginForm" autocomplete="off"&gt;
  &lt;input type='hidden' name='csrfmiddlewaretoken' value='mymQDzHWl2REXIfPMg2mJaLqDfaS1sD5' /&gt;
  &lt;div class="form-group marb20"&gt;
      &lt;label&gt;Username&lt;/label&gt;
      &lt;input name="username" id="account_l" type="text" placeholder="username or email" /&gt;
  &lt;/div&gt;
  &lt;div class="form-group marb8"&gt;
       &lt;label&gt;Password&lt;/label&gt;
       &lt;input name="password" id="password_l" type="password" placeholder="Enter your password" /&gt;
  &lt;/div&gt;
  &lt;div class="error btns login-form-tips" id="jsLoginTips"&gt;&lt;/div&gt;
  &lt;div class="auto-box marb38"&gt;
      &lt;label&gt;&lt;input type="checkbox" id="jsAutoLogin"&gt; Auto login&lt;/label&gt;
      &lt;a class="fr" href="forgetpwd.html"&gt;forget pwd?&lt;/a&gt;
  &lt;/div&gt;
  &lt;input class="btn btn-green" id="jsLoginBtn" type="submit" value="login &gt; " /&gt;
  {% csrf_token %}
  &lt;/form&gt;
  </code></pre>
  
  <p>in urls.py</p>
  
  <pre><code>from users.views import login
  urlpatterns = [
      url('^login/$',login, name='login'),
  ]
  </code></pre>
  
  <p>in settings.py</p>
  
  <pre><code>AUTH_USER_MODEL = 'users.UserProfile'
  AUTHENTICATION_BACKENDS = [
  "django.contrib.auth.backends.ModelBackend",
  'users.views.CustomBackend',
  ]
  </code></pre>
  
  <p>As a result, I can log in using the username and password, it prints: </p>
  
  <pre><code>[03/Feb/2019 23:40:06] "POST /login/ HTTP/1.1" 200 37066 # 
  </code></pre>
  
  <p>but when I log in with email and password, nothing change in my browser. On the terminal, it prints:</p>
  
  <pre><code>Not Found: /user/login/ 
  [03/Feb/2019 23:41:30] "POST /user/login/ HTTP/1.1" 404 2213
  </code></pre>
  
  <p>I don't know where this path "/user/login/" comes from, it's different from the one "/login/" before.</p>
  
  <p>SOLVED:
  I found the problem is caused by the codes I copy from the tutorial, there is a login.js including something like `$.ajax({ url:"/user/login/",}). And this happens when I use email to login.</p>