在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:adamcharnock/django-su开源软件地址:https://github.com/adamcharnock/django-su开源编程语言:Python 90.8%开源软件介绍:django-suLogin as any user from the Django admin interface, then switch back when done Authored by Adam Charnock, and some great contributors. Installation
And that should be it! Please see
External dependencies (optional, but recommended)The following apps are optional but will enhance the user experience:
Note that django-ajax-selects requires the following settings: AJAX_LOOKUP_CHANNELS = {'django_su': dict(model='auth.user', search_field='username')} Configuration (optional)There are various optional configuration options you can set in your # URL to redirect after the login.
# Default: "/"
SU_LOGIN_REDIRECT_URL = "/"
# URL to redirect after the logout.
# Default: "/"
SU_LOGOUT_REDIRECT_URL = "/"
# A function specifying the permissions a user requires in order
# to use the django-su functionality.
# Default: None
SU_LOGIN_CALLBACK = "example.utils.su_login_callback"
# A function to override the django.contrib.auth.login(request, user)
# view, thereby allowing one to set session data, etc.
# Default: None
SU_CUSTOM_LOGIN_ACTION = "example.utils.custom_login" UsageGo and view a user in the admin interface and look for a new "Login as" button in the top right. Once you have su'ed into a user, you can get exit back into your
original user by navigating to How toHow to Notify superuser when connected with another userThis option warns the superuser when working with another user as initially logged in. To activate this option perform:
How to use django-su with a custom user model (AUTH_USER_MODEL)Django-su should function normally with a custom user model. However, your ModelAdmin in your admin.py file will need tweaking as follows: # Within your admin.py file
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from . import models
@admin.register(models.CustomUser)
class CustomUserAdmin(UserAdmin):
# The following two lines are needed:
change_form_template = "admin/auth/user/change_form.html"
change_list_template = "admin/auth/user/change_list.html" This ensures the Django admin will use the correct template customisations for your custom user model. CreditsThis app was put together by Adam Charnock, but was largely based on ideas, code and comments at:
django-su is packaged using seed. |
2022-08-15
2022-08-17
2022-09-23
2022-08-18
2023-10-27
请发表评论