【问题标题】:Modifying the URL in Preview button in wagtail when editing a page编辑页面时修改 wagtail 中“预览”按钮中的 URL
【发布时间】:2019-10-24 10:59:58
【问题描述】:

我正在使用 wagtail 作为无头 CMS。我想让这个 CMS 的用户能够轻松地在 SPA 上查看页面的预览。我已经重写了 API 以在令牌的帮助下公开草稿页面。

我唯一坚持的部分是修改 Preview 按钮中的 URL 以重定向到 SPA,以便他们可以访问 API、获取数据并呈现页面。

有什么方法可以覆盖 preview 按钮的 URL,或者只是能够添加另一个操作来查看 SPA 上的页面预览?

【问题讨论】:

标签: wagtail


【解决方案1】:

Wagtail Headless

pip install wagtail-headless-preview

HEADLESS_PREVIEW_CLIENT_URLS = { 'default': 'http://localhost:8020/', }

将 HeadlessPreviewMixin 添加到您的页面类中:

from wagtail_headless_preview.models import HeadlessPreviewMixin

class MyWonderfulPage(HeadlessPreviewMixin, Page): pass

【讨论】:

    【解决方案2】:

    尝试使用 Ajax 来做这样的事情:

     function processAjaxData(response, urlPath){
     document.getElementById("content").innerHTML = response.html;
     document.title = response.pageTitle;
     window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);~}
    

    【讨论】:

      【解决方案3】:

      wagtail-headless-preview 旨在解决这个确切的问题:

      https://github.com/torchbox/wagtail-headless-preview

      【讨论】:

        猜你喜欢
        • 2019-08-22
        • 1970-01-01
        • 1970-01-01
        • 2019-01-12
        • 2019-06-16
        • 2016-11-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多