[Python] Wagtail default template field in_preview_panel is fine in dev but fails in production

Discussão em 'Python' iniciado por Stack, Abril 6, 2025.

  1. Stack

    Stack Membro Participativo

    In the default template from Wagtail even mentioned online here, there is a part:

    {# Force all links in the live preview panel to be opened in a new tab #}
    {% if request.in_preview_panel %}
    <base target="_blank">
    {% endif %}


    I extend this base template in my other templates.

    This is fine in dev, but when running the website in production, I face with this error:

    Exception while resolving variable 'in_preview_panel' in template 'home/home_page.html'.
    Traceback (most recent call last):
    File "/home/myusername/.local/lib/python3.12/site-packages/django/template/base.py", line 880, in _resolve_lookup
    current = current[bit]
    ~~~~~~~^^^^^
    TypeError: 'WSGIRequest' object is not subscriptable

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/home/myusername/.local/lib/python3.12/site-packages/django/template/base.py", line 890, in _resolve_lookup
    current = getattr(current, bit)
    ^^^^^^^^^^^^^^^^^^^^^
    AttributeError: 'WSGIRequest' object has no attribute 'in_preview_panel'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/home/myusername/.local/lib/python3.12/site-packages/django/template/base.py", line 896, in _resolve_lookup
    current = current[int(bit)]
    ^^^^^^^^
    ValueError: invalid literal for int() with base 10: 'in_preview_panel'

    During handling of the above exception, another exception occurred:

    ...


    I have no clue on what in_preview_panel is and why it behaves different in dev and prod.

    If I remove it, this case of error will be resolved. I have still other problems in my code. But, I do not want to remove this blindly or impacting the Wagtail admin. Instead, I want to understand what is happening.

    Continue reading...

Compartilhe esta Página