Reputation: 6065
Using Django 3.16, going into the admin console and managing a user (admin/auth/user/412/change/ in the example of user id 412), I attempt to change the user password by clicking on the link "you can change the password using this form".
But when I click on the link I get the error "User with ID "412/password" doesn't exist". It's like the URL settings aren't pulling the PK/ID out of the URL properly.
(You'll see I'm using the Grappelli styling for the admin console. I've tested it without Grappelli and I get the same errors.)
My urls.py has the usual line path('admin/', admin.site.urls)
.
Is there some reason why this might be happening, or something I can do about it?
thanks
John
Further investigation shows it's only when I use a custom User Admin form, as follows:
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserChangeForm
class UserAdmin(admin.ModelAdmin):
list_display = ('username','first_name', 'last_name','email','is_superuser','is_staff','is_active','last_login')
list_editable = ('is_active','is_superuser','is_staff')
form = UserChangeForm
list_filter = ('is_superuser','is_active','is_staff','last_login')
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
Is there something wrong with my line form = UserChangeForm
?
Upvotes: 0
Views: 655
Reputation: 6065
Ok, the problem was I was using a ModelAdmin form, rather than a UserAdmin form, as my custom class.
The custom class needs to look like this:
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
class UserAdmin(UserAdmin):
list_display = ('username','first_name', 'last_name', 'email','is_superuser','is_staff','is_active','last_login')
list_editable = ('is_active','is_superuser','is_staff')
list_filter = ('is_superuser','is_active','is_staff','last_login')
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
Upvotes: 3
Reputation: 321
If you are using AbstractBaseClass you need to give path of your CustomBackend in settings file
Upvotes: 0