我的头部因为撞墙而受伤...为什么内容面板无法识别我的DetailPage中的字段?一切正常,直到我将FieldPanel添加到content_panels。
哦,这也是使用2.0版本的wagtail。这似乎与字段类型无关,事件是一个简单的CharBlock触发此错误。
STACK TRACE
Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0000005F7CDB5598>
Traceback (most recent call last):
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\options.py", line 566, in get_field
return self.fields_map[field_name]
KeyError: 'links'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
...
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 766, in get_edit_handler
return edit_handler.bind_to_model(cls)
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 130, in bind_to_model
new.on_model_bound()
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 275, in on_model_bound
for child in self.children]
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 275, in <listcomp>
for child in self.children]
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 130, in bind_to_model
new.on_model_bound()
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 275, in on_model_bound
for child in self.children]
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 275, in <listcomp>
for child in self.children]
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 130, in bind_to_model
new.on_model_bound()
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 479, in on_model_bound
self.db_field = self.model._meta.get_field(self.field_name)
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\options.py", line 568, in get_field
raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: DetailPage has no field named 'links'
models.py 来自django.db导入模型
from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.core import blocks
from wagtail.core.blocks import ListBlock, URLBlock, StructBlock, TextBlock, CharBlock
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.search import index
class DetailPage(Page):
"""
Two column detail page with quick links on the left
"""
links = blocks.ListBlock(blocks.URLBlock(), null=True, blank=True)
body = RichTextField(blank=True)
content_panels = Page.content_panels + [
FieldPanel('links', classname="full"),
FieldPanel('body')
]
答案 0 :(得分:1)
ListBlock
和其他块类型(例如CharBlock
)不能与Django's model fields互换 - 它们不能直接在页面模型定义中使用,只能在StreamField中使用。