Code block
Python
Preview
{% code_block
language="python"
code="from wagtail.models import Page
def convert(page: Page, new_type: type[Page]) -> Page:
"""Swap
a
page
to
another
page
type."""
return new_type.objects.get(pk=page.pk)
"
%}
Parameters
| Name | Type | Requirement | Default | Choices | Description |
|---|---|---|---|---|---|
code
|
str
|
Required | — | — | The source code. |
language
|
str
|
Required | — | — | highlight.js language name, e.g. python. |
Select variant preset
Background colour
Viewport width
Zoom level
{% code_block code="foo" language="bar" %}
<figure class="code-block ">
<figcaption class="code-block__lang">python</figcaption>
<pre class="code-block__pre"><code class="language-python">from wagtail.models import Page
def convert(page: Page, new_type: type[Page]) -> Page:
"""Swap a page to another page type."""
return new_type.objects.get(pk=page.pk)
</code></pre>
</figure>