Django user user change_password

I am successfully using a custom model with django. The last thing you need to work is "AdminChangePasswordForm" for superusers to change any user password.

currently a password change link from admin: myapp: user gives 404

Answer.

Override get_urls

and override UserChangeForm to have the correct URL.

+5
source share
2 answers

This seems to be a β€œbug” in 1.7.x and fixed in 1.8.x that set the name of the url, so you need to override get_urls() :

 from django.contrib.auth.admin import UserAdmin as AuthUserAdmin from django.conf.urls import url class UserAdmin(AuthUserAdmin): def get_urls(self): return [ url(r'^(.+)/password/$', self.admin_site.admin_view(self.user_change_password), name='auth_user_password_change'), ] + super(UserAdmin, self).get_urls() 

URL:

 password_change_url = urlresolvers.reverse('admin:auth_user_password_change', args=(1,)) 
+2
source

So I had a similar problem. When I tried to change the user password from admin, I got a url for "/ admin / accounts / siteuser / password /" (siteuser is the name of my user model) and a 404 error with this message: "User object with primary key u" password " does not exist." Research has shown that the problem is due to an error in django-authtools (1.4.0), since I used the NamedUserAdmin class to inherit.

So, the solution is also (if you need to inherit from any custom UserAdmin, such as NamedUserAdmin, from django-authtools):

 from django.contrib.auth.forms import UserChangeForm from authtools.admin import NamedUserAdmin class SiteUserAdmin(NamedUserAdmin): ... form = UserChangeForm ... 

or just inherit from the standard django UserAdmin:

 from django.contrib.auth.admin import UserAdmin class SiteUserAdmin(UserAdmin): pass 
0
source

Source: https://habr.com/ru/post/1233813/


All Articles