custom admin urls routing wrong? #804
-
|
in one of my child model i have a change password custom urls def get_urls(self):
return [
path(
'<path:object_id>/password/',
self.admin_site.admin_view(self.mymodel_change_password),
name='mymodel_password_change',
),
] + super().get_urls()and when i try to access: the url become: and 1/password is catched as object id for the change view Any help ? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
anyone ? |
Beta Was this translation helpful? Give feedback.
-
|
The issue is caused by using Fix: don’t use def get_urls(self):
return [
path(
'<int:object_id>/password/',
self.admin_site.admin_view(self.mymodel_change_password),
name='mymodel_password_change',
),
] + super().get_urls()This prevents |
Beta Was this translation helpful? Give feedback.
-
|
@bckohan I think we can convert this into a discussion |
Beta Was this translation helpful? Give feedback.
The issue is caused by using
<path:object_id>, which is greedy and captures1/passwordas the object ID, so Django routes it to the change view.Fix: don’t use
<path:object_id>in admin URLs. Use a non-greedy converter instead.This prevents
passwordfrom being swallowed by the change view and resolves the URL correctly.