Django - Override admin site's login form

Holá
I found a very simple solution.
You just need to modify the urls.py fle of the project (note, not the application one)

  1. In your PROJECT folder locate the file urls.py.
  2. Add this line to the imports section
    from your_app_name import views
  3. Locate this line
    url(r'^admin/', include(admin.site.urls))
  4. Add above that line the following
    url(r'^admin/login/', views.your_login_view),

This is an example

from django.conf.urls import include, url
from django.contrib import admin

from your_app import views

urlpatterns = [
    url(r'^your_app_start/', include('your_app.urls',namespace="your_app_name")),

    url(r'^admin/login/', views.your_app_login),
    url(r'^admin/', include(admin.site.urls)),
]

AdminSite has a login_form attribute that you can use to override the form used.

Subclass AdminSite and then use an instance of your subclass instead of django.contrib.admin.site to register your models in the admin, in urls.py, etc.

It's all in the documentation.


This code in urls.py works fine for me (Django version 1.5.1):

from django.contrib import admin
from my.forms import AuthenticationForm

admin.autodiscover()
admin.site.login_form = AuthenticationForm