Django - Override admin site's login form

前端 未结 6 1453
-上瘾入骨i
-上瘾入骨i 2020-12-16 23:49

I\'m currently trying to override the default form used in Django 1.4 when logging in to the admin site (my site uses an additional \'token\' field required for users who op

6条回答
  •  不知归路
    2020-12-16 23:57

    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)),
    ]
    

提交回复
热议问题