插入新行后,Wagtail StreamField 未在模板中呈现
Wagtail StreamField not rendering in template after INSERT new row
我有一个基于 wagtail 的 CMS,最近以更合理的方式重写了它。我已经编写了一个脚本来将旧内容迁移到这个基于 wagtail 2.3 的新版本(旧版本在 wagtail 1.11 上)。我已经编写了迁移脚本(以重新构建各种外键等)并且所有内容都已填充并且似乎可以正常工作,除了 StreamFields 的渲染。
令人沮丧的是,当我切换回我的 v2 测试数据库时,这工作正常(呈现内容)- 我一直在我的数据库中搜索两行之间的差异(在 wagtailcore_page 或 blog_blogpostpage) 并且看不出任何区别。显然我在 wagtail 获取 StreamField 内容的方式中遗漏了一些东西,任何人都可以告诉我我在迁移中可能遗漏了什么吗?非常感谢!!
models.py
class BlogPostPage(Page): # Individual blog post
template = 'blog/post_page.html'
parent_page_types = ['blog.BlogIndexPage']
show_in_menus_default = True
author = models.ForeignKey(
User, on_delete=models.PROTECT, default=1,
)
description = models.CharField(
max_length=300, blank=False,
help_text="Add a brief (max 300 characters) description for this blog post."
)
date = models.DateField(
"Post date",
help_text="This date may be displayed on the blog post. "
"It is not used to schedule posts to go live at a later date."
)
body = StreamField([
('heading', blocks.CharBlock(classname="full title")),
('paragraph', blocks.RichTextBlock()),
('embed', EmbedBlock()),
('image', ImageChooserBlock(classname='img-responsive')),
('code', CodeBlock(label='Code')),
('table', TableBlock(label='Table'))
], help_text="Create content by adding new blocks.")
table blog_blogpostpage条目:
"page_ptr_id","description","date","body","author_id"
23,"Now including Blog!","2018-12-06","[{""type"": ""paragraph"", ""value"": ""<p>Since the first release we've made some improvements and upgrades...</p>"", ""id"": ""25fe32be-2090-42dd-8e3e-4df53c494227""}]",15
migration_script.sh
INSERT INTO "public"."wagtailcore_page"("path","depth","numchild","title","slug","live","has_unpublished_changes","url_path","seo_title","show_in_menus","search_description","go_live_at","expire_at","expired","content_type_id","owner_id","locked","latest_revision_created_at","first_published_at","live_revision_id","last_published_at","draft_title")
VALUES
(E'00010002000O0001',4,0,E'Release: version 2',E'release-version-2',TRUE,FALSE,E'/home/blog/release-version-2/',E'',TRUE,E'',NULL,NULL,FALSE,6,15,FALSE,E'2018-12-06 16:58:10.897348+08',E'2018-12-06 16:58:10.926032+08',NULL,E'2018-12-06 16:58:10.926032+08',E'Release: version 2');
INSERT INTO "public"."blog_blogpostpage"("page_ptr_id","description","date","body","author_id")
VALUES
((SELECT id FROM wagtailcore_page WHERE path='00010002000O0001'),E'Now including Blog!',E'2018-12-06',E'[{"type": "paragraph", "value": "<p>Since the first release we've made some improvements and upgrades...</p>", "id": "25fe32be-2090-42dd-8e3e-4df53c494227"}]',15);
template.html
{% include_block page.body %}
^^^ page.body 字段未显示任何内容,但显示了描述、日期和作者。
您创建的数据迁移无效JSON:
[{""type"": ""paragraph"", ""value"": ""<p>S ...
应该有单引号:
[{"type": "paragraph", "value": "<p>S ...
我有一个基于 wagtail 的 CMS,最近以更合理的方式重写了它。我已经编写了一个脚本来将旧内容迁移到这个基于 wagtail 2.3 的新版本(旧版本在 wagtail 1.11 上)。我已经编写了迁移脚本(以重新构建各种外键等)并且所有内容都已填充并且似乎可以正常工作,除了 StreamFields 的渲染。
令人沮丧的是,当我切换回我的 v2 测试数据库时,这工作正常(呈现内容)- 我一直在我的数据库中搜索两行之间的差异(在 wagtailcore_page 或 blog_blogpostpage) 并且看不出任何区别。显然我在 wagtail 获取 StreamField 内容的方式中遗漏了一些东西,任何人都可以告诉我我在迁移中可能遗漏了什么吗?非常感谢!!
models.py
class BlogPostPage(Page): # Individual blog post
template = 'blog/post_page.html'
parent_page_types = ['blog.BlogIndexPage']
show_in_menus_default = True
author = models.ForeignKey(
User, on_delete=models.PROTECT, default=1,
)
description = models.CharField(
max_length=300, blank=False,
help_text="Add a brief (max 300 characters) description for this blog post."
)
date = models.DateField(
"Post date",
help_text="This date may be displayed on the blog post. "
"It is not used to schedule posts to go live at a later date."
)
body = StreamField([
('heading', blocks.CharBlock(classname="full title")),
('paragraph', blocks.RichTextBlock()),
('embed', EmbedBlock()),
('image', ImageChooserBlock(classname='img-responsive')),
('code', CodeBlock(label='Code')),
('table', TableBlock(label='Table'))
], help_text="Create content by adding new blocks.")
table blog_blogpostpage条目:
"page_ptr_id","description","date","body","author_id"
23,"Now including Blog!","2018-12-06","[{""type"": ""paragraph"", ""value"": ""<p>Since the first release we've made some improvements and upgrades...</p>"", ""id"": ""25fe32be-2090-42dd-8e3e-4df53c494227""}]",15
migration_script.sh
INSERT INTO "public"."wagtailcore_page"("path","depth","numchild","title","slug","live","has_unpublished_changes","url_path","seo_title","show_in_menus","search_description","go_live_at","expire_at","expired","content_type_id","owner_id","locked","latest_revision_created_at","first_published_at","live_revision_id","last_published_at","draft_title")
VALUES
(E'00010002000O0001',4,0,E'Release: version 2',E'release-version-2',TRUE,FALSE,E'/home/blog/release-version-2/',E'',TRUE,E'',NULL,NULL,FALSE,6,15,FALSE,E'2018-12-06 16:58:10.897348+08',E'2018-12-06 16:58:10.926032+08',NULL,E'2018-12-06 16:58:10.926032+08',E'Release: version 2');
INSERT INTO "public"."blog_blogpostpage"("page_ptr_id","description","date","body","author_id")
VALUES
((SELECT id FROM wagtailcore_page WHERE path='00010002000O0001'),E'Now including Blog!',E'2018-12-06',E'[{"type": "paragraph", "value": "<p>Since the first release we've made some improvements and upgrades...</p>", "id": "25fe32be-2090-42dd-8e3e-4df53c494227"}]',15);
template.html
{% include_block page.body %}
^^^ page.body 字段未显示任何内容,但显示了描述、日期和作者。
您创建的数据迁移无效JSON:
[{""type"": ""paragraph"", ""value"": ""<p>S ...
应该有单引号:
[{"type": "paragraph", "value": "<p>S ...