FlipperPA / wagtailcodeblock

StreamField code blocks for the Wagtail CMS with real-time PrismJS Syntax Highlighting.
BSD 3-Clause "New" or "Revised" License
156 stars 29 forks source link

Error ValueError: dictionary update sequence element #0 has length 0; 2 is required when it's rendered as a block #46

Closed ealvan closed 4 months ago

ealvan commented 4 months ago

Details: python 3.10 wagtail 6.1 wagtailcodeblock 1.29.0.2

When I implement this codeblock with all configurations like this:

INSTALLED_APPS = [
    "wagtailcodeblock"
]

WAGTAIL_CODE_BLOCK_LINE_NUMBERS = True
WAGTAIL_CODE_BLOCK_COPY_TO_CLIPBOARD = True
WAGTAIL_CODE_BLOCK_THEME = 'dark'

WAGTAIL_CODE_BLOCK_LANGUAGES = (
    ('bash', 'Bash/Shell'),
    ('ruby', 'Ruby'),
    ('rust', 'Rust'),
    ('css', 'CSS'),
    ('javascript', 'Javascript'),
    ('html', 'HTML'),
    ('json', 'JSON'),
    ('python', 'Python'),
    ('django', 'Django/Jinja2'),
    ('java', 'Java'),
    ('cpp', 'C++'),    
    ('sql', 'SQL'),
    ('typescript', 'TypeScript'),
    ('tcl', 'Tcl'),
    ('git', 'Git'),
    ('cmake', 'CMake'),
    ('csharp', 'C#'),
    ('docker', 'Docker'),
    ('go', 'Go'),
    ('yaml', 'YAML'),
    ('latex', 'LaTeX'),
    ('makefile', 'Makefile'),
    ('nginx', 'nginx'),
    ('perl', 'Perl'),
    ('php', 'PHP'),
    ('powershell', 'PowerShell'),
    ('sparql', 'SPARQL'),
    ('solidity', 'Solidity (Ethereum)'),
    ('yaml', 'YAML'),
)

And I use in a streamblock:


class StreamBlockPageTest(Page):
    page_description = "Test page"
    template = "test_page.html"
    body = StreamField([
        ('heading', blocks.CharBlock(form_classname="title", label='Titulo')),
        ("paragraph", blocks.RichTextBlock(label='Parrafo')),
        ("code", CodeBlock(label='Code')),
    ], blank=True)

    content_panels = Page.content_panels + [
        FieldPanel('body')
    ]

Admin panel goes well: image

But When I use my template:

{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block body_class %}template-blogtestpage{% endblock %}

{% block content %}
    <h1>titulo : {{page.title}}</h1>
    <p class="meta" >{{page.date}}</p>

    <div class="author">
        {{page.author}}
    </div>

    <div class="body">
        {% for block in page.body %}
            {% include block %}
        {% endfor %} 
    </div>
{% endblock %}

The error says:

    new_context = self.get_context(value, parent_context=dict(context))
ValueError: dictionary update sequence element #0 has length 0; 2 is required

Is this a new error due to updating wagtail 6.1?

ealvan commented 4 months ago

the error isn't the block, but it was the use of {% include block %} instead of using {{block}}

#My error was using the include tag instead of just use the block:

<div class="body">
    {% for block in page.body %}
        {% if block.block_type == "code" %}
            {{ block }}
        {% else %}
            {% include block %}
        {% endif %}

    {% endfor %} 
</div>

With this code, it should work well