0

我正在尝试在 wagtails 模型管理员中添加新视图。但我面临错误。我正在尝试按照此问题中解释的步骤进行操作。https://github.com/wagtail/wagtail/issues/3336

这是我的代码片段。

class CustomButtonHelper(ButtonHelper):
    # Define classes for our button, here we can set an icon for example
    view_button_classnames = ["button-small", "button-secondary"]

    def nginx_button(self, pk, classnames_add=None, classnames_exclude=None):
        if classnames_add is None:
            classnames_add = []
        if classnames_exclude is None:
            classnames_exclude = []
        classnames = self.inspect_button_classnames + classnames_add
        cn = self.finalise_classname(classnames, classnames_exclude)
        return {
            "url": self.url_helper.get_action_url("nginx_conf", quote(pk)),
            "label": "Nginx Conf",
            "classname": cn,
            "title": "Inspect this %s" % self.verbose_name,
        }

    def get_buttons_for_obj(
        self, obj, exclude=None, classnames_add=None, classnames_exclude=None
    ):
        btns = super().get_buttons_for_obj(
            obj, exclude, classnames_add, classnames_exclude
        )
        if "nginx" not in (exclude or []):
            btns.append(self.nginx_button(obj))
        return btns


class ClientAdmin(ModelAdmin):
    button_helper_class = TenantButtonHelper
    nginx_conf_view_class = GenerateNginxConf

    def nginx_conf_view(self, request, instance_pk):
        kwargs = {'model_admin': self, 'instance_pk': instance_pk}
        # May be need here to customize custom functionality
        view_class = self.nginx_conf_view_class
        return view_class.as_view(**kwargs)(request)

    def get_admin_urls_for_registration(self):
        urls = super().get_admin_urls_for_registration()
        urls = urls + (
            url(self.url_helper.get_action_url_pattern('nginx_conf'),
                self.nginx_conf_view,
                name=self.url_helper.get_action_url_name('nginx_conf')),
        )
        return urls

错误页面。 在此处输入图像描述

我不知道我错过了什么。

4

0 回答 0