question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a setting to disable preview / view live functionality

See original GitHub issue

Problem

I want to run Wagtail as a headless CMS. In my example, I only want to use Wagtail for a mobile app. This means I don’t have a frontend to use the preview functionality for pages.

Proposed solution

Introduce a new setting WAGTAIL_HEADLESS_DISABLE_PREVIEW that would disable the Preview / View live buttons for pages when set to True.

For now, there are alternatives like serving a page with some content saying Preview is not supported but more user-friendly would be to not show the buttons at all. Another option is to override some admin templates but this is also not ideal.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
gasmancommented, Nov 6, 2019

I’d be keen to look at alternatives to adding a new setting - if Wagtail isn’t catering for a particular use-case then we should improve the design of Wagtail to accommodate it, not just add a new setting and conditional on top and call it done.

As @zerolab pointed out on Slack, it would make logical sense that setting preview_modes to an empty list should disable previewing - it looks like it’s only failing because of the template-level logic. My preference would be to fix that behaviour.

0reactions
thibaudmartinezcommented, Apr 18, 2020

Hi there,

I am currently using Wagtail nightly 2.9.dev20200418 as I wanted to use the “disable preview” feature.

The live button is properly hidden, but I ran into the following problem.

Let’s say I define the model SomePage for which I disable the preview.

class SomePage(Page):
    preview_modes = []

I create a page from this model and save it has a draft. When I go to the admin home page and click on the button “DRAFT” of the row corresponding to the created page I get the following error.

Internal Server Error: /admin/pages/4/view_draft/
Traceback (most recent call last):
  File "/home/thibaud/workspace/bugs/draft-btn/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/thibaud/workspace/bugs/draft-btn/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/thibaud/workspace/bugs/draft-btn/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/thibaud/workspace/bugs/draft-btn/env/lib/python3.7/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/home/thibaud/workspace/bugs/draft-btn/env/lib/python3.7/site-packages/wagtail/admin/urls/__init__.py", line 109, in wrapper
    return view_func(request, *args, **kwargs)
  File "/home/thibaud/workspace/bugs/draft-btn/env/lib/python3.7/site-packages/wagtail/admin/auth.py", line 168, in decorated_view
    return view_func(request, *args, **kwargs)
  File "/home/thibaud/workspace/bugs/draft-btn/env/lib/python3.7/site-packages/wagtail/admin/views/pages.py", line 610, in view_draft
    return page.make_preview_request(request, page.default_preview_mode)
  File "/home/thibaud/workspace/bugs/draft-btn/env/lib/python3.7/site-packages/wagtail/core/models.py", line 1398, in default_preview_mode
    return self.preview_modes[0][0]
IndexError: list index out of range

I also get this error when I click the “VIEW DRAFT” button of the page on the list page view.

It would be nice to hide these buttons for a page when preview_modes = [] to prevent actions leading to errors.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to disable Preview Pane in File Explorer - Ablebits
Go to the View tab. To disable the Preview pane, simply click it once. Also, you can use the Alt + P shortcut....
Read more >
Preview mode - Optimize Resource Hub - Google Support
We recommend using preview mode on Chrome. Safari users must go to Preferences > Privacy and then clear Prevent cross-site tracking to use...
Read more >
How to disable Preview Pane in File Explorer of Windows 11/10
Open Turn off Preview Pane setting; Select the Enabled option; Press the Apply button; Press the OK button. Let's have a look at...
Read more >
Enable Preview features to get early access - Power Platform
In a Unified Interface app · Sign in to Power Apps. · Select your environment from the top-right corner, and select Settings (...
Read more >
How to Disable the Preview Pane in the Windows 10 Mail App ...
In Microsoft Outlook (2019-2013): Select View > Reading Pane, and then select Off from the drop-down menu. This article explains how to disable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found