How to make Django admin site accessed by non-staff user?

后端 未结 2 1487
说谎
说谎 2021-02-06 10:53

I would like to implement a 2nd admin site which provides a subset of feature of the primary admin site. That\'s possible and described in the Django docs

However, I wou

2条回答
  •  感动是毒
    2021-02-06 11:46

    I think that your approach should now be possible: http://code.djangoproject.com/ticket/14434 (closed 5 weeks ago)

    However, the explicit "is_staff" check is still done in two places (apart from the staff_member_required decorator):

    • django.contrib.admin.forms.AdminAuthenticationForm.clean()

      On top of "has_permission()" you'd need to provide your non-staff AdminSite with a "login_form" that doesn't do the is_staff check, so could just subclass and adjust clean() accordingly.

    • templates/admin/base.html

      would need to be slightly customized. The div with id "user-tools" is only shown for active staff members. I'm assuming that's done because the login form also uses this template, and someone could be logged in as an active non-staff member but still should'nt see those links.

提交回复
热议问题