The above approach no longer works on django 1.9. Another approach might be to override the auth form used in the view as:
class EmailLoginForm(AuthenticationForm): def clean(self): try: self.cleaned_data["username"] = get_user_model().objects.get(email=self.data["username"]) except ObjectDoesNotExist: self.cleaned_data["username"] = "a_username_that_do_not_exists_anywhere_in_the_site" return super(EmailLoginForm, self).clean()
Then, by defining the login URL, determine how it is:
url(r'^login/$', django.contrib.auth.views.login, name="login", kwargs={"authentication_form": EmailLoginForm}), url(r'^', include('django.contrib.auth.urls')),
The best thing about the above approach is that you don’t really touch the authentication process. This is not exactly a “clean” solution, but it is a quick solution. When you determine the login path before enabling auth.urls, it will be evaluated instead of the basic login form
source share