Django自定义用户admin change_password [英] Django custom user admin change_password
问题描述
我已成功将自定义用户模型与django结合使用.要工作的最后一件事是让超级用户更改任何用户密码的"AdminChangePasswordForm".
I'm successfully using a custom user model with django. The last thing to get working is the "AdminChangePasswordForm" for superusers to change any users password.
当前admin:myapp:user的更改密码链接给出了404
currently the change password link from admin:myapp:user gives a 404
答案.
覆盖get_urls
Override get_urls
并覆盖UserChangeForm以获取正确的网址.
and override UserChangeForm to have the correct url.
推荐答案
所以我遇到了类似的问题.当我尝试从admin更改用户密码时,我将URL设置为"/admin/accounts/siteuser/password/"(siteuser是我的自定义用户模型的名称),并出现404错误,并显示以下消息:主键为u的用户对象"密码"不存在."调查表明问题出在我使用NamedUserAdmin类继承时,是由于django-authtools(1.4.0)中的错误所致.
So I had similar problem. When I tried to change user password from admin I got url to "/admin/accounts/siteuser/password/" (siteuser is the name of my custom user model) and 404 error with this message: "user object with primary key u'password' does not exist." The investigation showed that the problem was due to bug in django-authtools (1.4.0) as I used NamedUserAdmin class to inherit from.
因此解决方案是(如果您需要从django-authtools的任何自定义UserAdmin(例如NamedUserAdmin)继承):
So the solution is either (if you need to inherit from any custom UserAdmin like NamedUserAdmin from django-authtools):
from django.contrib.auth.forms import UserChangeForm
from authtools.admin import NamedUserAdmin
class SiteUserAdmin(NamedUserAdmin):
...
form = UserChangeForm
...
或仅继承默认的django UserAdmin:
or just inherit from default django UserAdmin:
from django.contrib.auth.admin import UserAdmin
class SiteUserAdmin(UserAdmin):
pass
这篇关于Django自定义用户admin change_password的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!