继承 AdminSite 但无法访问父 class 中的 get_app_list(对象没有属性 'get_app_list')

Inherit AdminSite but can't get access to get_app_list in parent class (object has no attribute 'get_app_list')

我正在自定义我的管理页面,但在访问 django.contrib.admin.AdminSite 方法时遇到了一些问题。我是 Django 的新手,所以如果我的错误是愚蠢的,请放轻松

在这里,我尝试扩展 AdminSite 并在我的 admin.py

中覆盖 index
class MyAdmin(admin.AdminSite):
    @never_cache
    def index(self, request, extra_context=None):
        """
        Displays the main admin index page, which lists all of the installed
        apps that have been registered in this site.
        """
        app_list = super(MyAdmin, self).get_app_list(request)

        context = dict(
            self.each_context(request),
            title=self.index_title,
            app_list=app_list,
        )
        context.update(extra_context or {})

        request.current_app = super(MyAdmin, self).name

        return TemplateResponse(request, super(MyAdmin, self).index_template or
                                'admin/testing.html', context)

admin_site = MyAdmin(name='myadmin')

我也试过保持

self.get_app_list(request)

但都给了我同样的问题

AttributeError at /myadmin/ 'super' object has no attribute 'get_app_list'

AttributeError at /myadmin/ 'self' object has no attribute 'get_app_list'

我已经用正确的设置更改了 urls.pysettings.py

非常感谢任何帮助

不确定你是从哪里得到这个想法的,但是查看源代码,django 1.9 中引入了 get_app_list 辅助方法。

这里是源代码的链接。

很明显,您使用的是 django <= 1.8.5