有没有办法改变按钮的文字?添加子页面 默认的页面模式 鹡鸰?
Wagtail提供了一个钩子系统来覆盖整个管理界面的功能。其中一个可用的钩子是 构造_页面列表_按钮。 让你在渲染前自定义按钮的最终列表。
你将需要在任何应用程序中创建一个叫做 wagtail_hooks.py
Wagtail将在开始时执行。请看- https:/docs.wagtail.ioenstablereferencehooks.html#hooks。
在源码中,你可以看到 添加页面按钮生成 以供参考如何添加它们。
wagtail_hooks.py
from wagtail.core import hooks
from wagtail.admin.widgets import Button, PageListingButton
@hooks.register('construct_page_listing_buttons')
def replace_page_listing_button_item(buttons, page, page_perms, is_parent=False, context=None):
for index, button in enumerate(buttons):
# basic code only - recommend you find a more robust way to confirm this is the add child page button
if button.label == 'Add child page'
new_button = Button(...)
buttons[index] = new_button # update the matched button with a new one (note. PageListingButton is used in page listing)