Changing password in Django Admin

前端 未结 7 1728
一个人的身影
一个人的身影 2020-12-14 19:49

I recently created the admin.py based in the Django Project Document:

https://docs.djangoproject.com/en/dev/topics/auth/customizing/#django.contrib.auth.models

7条回答
  •  一个人的身影
    2020-12-14 20:11

    For a django version independent solution you can reverse the url in the UserChangeForm.__init__ with something like:

    from django.core.urlresolvers import reverse
    
    class UserChangeForm(forms.ModelForm):
        password = ReadOnlyPasswordHashField()
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.fields['password'].help_text = (
                "Raw passwords are not stored, so there is no way to see "
                "this user's password, but you can  "
                "Change the Password using this form."
            ) % reverse_lazy('admin:auth_user_password_change', args=[self.instance.id])
    

提交回复
热议问题