14👍
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.
22👍
Holá
I found a very simple solution.
You just need to modify the urls.py fle of the project (note, not the application one)
- In your PROJECT folder locate the file urls.py.
- Add this line to the imports section
from your_app_name import views
- Locate this line
url(r'^admin/', include(admin.site.urls))
- 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)),
]
- Django template img src not working
- How to mock chained function calls in python?
- Django order_by a property
- TypeError: create_superuser() missing 1 required positional argument: 'profile_picture'
- How to paginate "Change List" page in Django admin?
13👍
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
2👍
I know this is an old thread, but I wanted to add something it helped me find, in case it can help others.
I’m using a special remote auth (Shibboleth) and overriding the admin login_form wouldn’t be enough. I have a view that sets cookies and return variables and redirects to the remote auth provider, etc.
So the way I did it was:
from my_app.views import user_login, user_logout
admin.autodiscover()
admin.site.login = user_login
admin.site.logout = user_logout
Works great!
Thanks to @dgk
- Pycharm Django Debugging is really slow
- Is there a command for creating an app using cookiecutter-django?
- Django 1.7 upgrade error: AppRegistryNotReady: Models aren't loaded yet
1👍
I redirect to a unique login url (I’m using django 2.1 and python 3.6 f-strings):
from apps import admin
from django.urls import path, include
from django.shortcuts import redirect
urlpatterns = [
path(
'admin/login/',
lambda r: redirect(
f"/login?{r.META['QUERY_STRING']}" if r.META['QUERY_STRING'] \
else '/login'
)
),
path('admin/', admin.site.urls),
]
- In django, is there a way to directly annotate a query with a related object in single query?
- Django request.user.is_authenticated is always true?
- Django template rows of multiple items
- Python-social-auth with Django: ImportError: No module named 'social_django'