python - Wagtail 管理模板中的 render() 意外关键字错误

标签 python django wagtail

我正在从 Django 1.11 和 Wagtail 2.0 升级到两者的最新版本。一切似乎都正常,除了当我尝试编辑或创建一种特定页面类型时出现 Django 错误

File "/Users/########/new_blog/lib/python3.6/site-packages/django/template/base.py" in resolve
  698.                 new_obj = func(obj, *arg_vals)

File "/Users/########/new_blog/lib/python3.6/site-packages/wagtail/admin/templatetags/wagtailadmin_tags.py" in render_with_errors
  247.         return bound_field.as_widget()

File "/Users/########/new_blog/lib/python3.6/site-packages/django/forms/boundfield.py" in as_widget
  93.             renderer=self.form.renderer,

Exception Type: TypeError at /admin/pages/6/edit/
Exception Value: render() got an unexpected keyword argument 'renderer'

此处完整堆栈跟踪:https://gist.github.com/chrxr/0427c6f8bd884828bf332d7cf6290447

我确信这与 Django 2.0+ 的更改有关,并且由于它只是一页,我很确定它与我的模型有关,但我不知道模型的哪一部分可能导致此问题。谁能帮我找出问题所在?

有问题的模型是“Blogpage”,可以在此处看到:

class BlogPage(RoutablePageMixin, Page):
subtitle = models.CharField(max_length=255, null=True, blank=True)
main_image = models.ForeignKey(
    'wagtailimages.Image',
    null=True,
    blank=True,
    on_delete=models.SET_NULL,
    related_name='+'
)
date = models.DateField("Post date", null=True, blank=True)
intro = models.CharField(max_length=250, null=True, blank=True)
body = StreamField([
    ('heading', CharBlock(classname="full title", icon='title')),
    ('paragraph', RichTextBlock(icon='pilcrow')),
    ('image', ImageChooserBlock(icon='image')),
    ('codeblock', TextBlock(icon='cogs')),
    ('markdown', MarkDownBlock()),
    ('real_codeblock', CodeBlock()),
], blank=True, null=True)
tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
listing_intro = RichTextField(null=True, blank=True)
listing_image = models.ForeignKey(
    'wagtailimages.Image',
    null=True,
    blank=True,
    on_delete=models.SET_NULL,
    related_name='+'
  )

search_fields = Page.search_fields + [
    index.SearchField('intro'),
    index.SearchField('body'),
]

content_panels = Page.content_panels + [
    FieldPanel('subtitle'),
    ImageChooserPanel('main_image'),
    FieldPanel('date'),
    FieldPanel('intro'),
    StreamFieldPanel('body'),
    FieldPanel('tags'),
]

promote_panels = Page.promote_panels + [
    FieldPanel('listing_intro'),
    ImageChooserPanel('listing_image'),
]

@property
def home_page(self):
    return self.get_parent()

@property
def next_blog(self):
    blogs = BlogPage.objects.filter(live=True).order_by('-date')
    current_index = blogs.index(self)

def get_absolute_url(self):
    return self.full_url

@route(r'^$', name='normal_blog')
def normal_blog(self, request):
    site_root = self.get_parent()

    return render(request, self.template, {
        'self': self,
    })

@route(r'^amp/$', name='amp_blog')
def amp_blog(self,request):
    context = self.get_context(request)
    context['is_amp'] = True
    context['base_template'] = 'base_amp.html'
    response = TemplateResponse(request, self.template, context)
    return response

如果它有用,可以在此处查看完整的 280 行模型文件:

https://github.com/chrxr/blog_project/blob/upgrade-to-latest/blog/models.py#L118

我怀疑它与 taggit 有关,或者至少我在网上发现了一些类似的问题,但我真的不确定......

FWIW这是我的要求.txt

Django==2.1.7
Jinja2==2.8
Markdown==2.6.2
MarkupSafe==0.23
Pillow>2.8.2
PyYAML==3.11
Pygments==2.0.2
Unidecode==0.04.18
Willow>0.2.2
ansible==2.0.1.0
beautifulsoup4==4.4.0
django-appconf==1.0.3
django-compressor==1.5
django-medusa==0.3.0
django-modelcluster==4.1
django-sendfile==0.3.11
django-taggit==0.22.2
django-treebeard==4.0.1
djangorestframework==3.9.2
ecdsa==0.13
elasticsearch==6.3.1
google-api-python-client==1.5.0
html5lib==0.999
httplib2==0.9.2
oauth2client==2
paramiko==2.4.2
postgres==2.1.2
psycopg2==2.7.4
pyasn1==0.1.9
pyasn1-modules==0.0.8
pycrypto==2.6.1
python-memcached==1.59
pytz==2015.4
requests==2.7.0
rsa==3.3
simplejson==3.8.2
six==1.9.0
uritemplate==3.0.0
urllib3==1.24.1
wagtail==2.4
wagtailfontawesome==1.1.3
wheel==0.24.0

谢谢!

最佳答案

您需要将 django-taggit 升级到 0.23.0 - 之前的版本是 not compatible with Django 2.1 .

关于python - Wagtail 管理模板中的 render() 意外关键字错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55284238/

相关文章:

检查变量是否作为 kwargs 传递的 Pythonic 方法?

python - Django -- 'data' 不是注册的命名空间

python - 如何用可调用类装饰类方法?

python - 如何在 django html 中的 UI 上按列对列表进行排序

html - 图像拒绝覆盖 div 中的另一个图像

python - 如何将 formbuilder 制作的表单添加到 Wagtail 中的每个页面?

wagtail - 使用外键集编辑站点设置时生成 KeyError

wagtail - 如何将 Wagtail 图像选择器面板限制为集合

python - PyCharm 错误加载包列表

python - 如何在 Django 模板中进行数学运算?