urlpattern
更改视图位于admin /options.py中:
url(r'^(.+)/$',
wrap(self.change_view),
name='%s_%s_change' % info),
您会发现它向实例的change_view
方法发送了一个请求。ModelAdmin
该change_view
方法也位于admin/options.py中:
def change_view(self, request, object_id, form_url='', extra_context=None):
...
它确实接受一个参数object_id
。
The reason of the missing match of reverse
is that the urlpattern
above does not accept named parameter, if you change it to something like
url(r'^(?P<object_id>.+)/$',
wrap(self.change_view),
name='%s_%s_change' % info),
The urlresolvers.reverse('admin:cards_card_change', kwargs={'object_id':92})
should work.
I've no idea whether it was intended to avoid some edge cases or it's just a bug and there's already a ticket fixing this. I'll check it later.