Python 3.8、Wagtail 5.1、Ubuntu 20.04 和 pipelinev 来固定所有依赖项
我通过处理从 Wagtail 4.0 到 5.0 的每个小版本,成功升级了一个小站点。当我升级到 5.1 时,我现在在管理员和网站中都收到上述
{% image ... %}
标签的错误。这段代码在 5.0 版本上运行没有问题。两个图像参考均来自数据库记录。从管理模板:
{% extends "wagtailadmin/base.html" %}
{% load wagtailimages_tags %}
{% block branding_logo %}
{% image settings.main.SiteSettings.logo_admin width-150 %}
{% endblock %}
这是主页模板中的
{% image ... %}
标签:
{% image settings.main.SiteSettings.logo_admin height-85 alt="Home" title="Home" style="position:relative; margin-bottom:-4px" %}
我怀疑此错误与升级注意事项:图像再现现在默认缓存有关。该网站的流量如此之低,以至于不需要缓存图像,因此我不想费心设置缓存。然而,Wagtail 现在强制使用缓存吗?或者Wagtail代码有错误?有没有办法在不设置缓存的情况下解决此错误?
回溯的相关部分:
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/venv/lib/python3.8/site-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/venv/lib/python3.8/site-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
File "/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 63, in render
result = block.nodelist.render(context)
File "/venv/lib/python3.8/site-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/venv/lib/python3.8/site-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/venv/lib/python3.8/site-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
File "/venv/lib/python3.8/site-packages/wagtail/images/templatetags/wagtailimages_tags.py", line 129, in render
rendition = get_rendition_or_not_found(
File "/venv/lib/python3.8/site-packages/wagtail/images/shortcuts.py", line 13, in get_rendition_or_not_found
return image.get_rendition(specs)
File "/venv/lib/python3.8/site-packages/wagtail/images/models.py", line 455, in get_rendition
Rendition.cache_backend.set(cache_key, rendition)
File "/venv/lib/python3.8/site-packages/django/core/cache/backends/locmem.py", line 53, in set
pickled = pickle.dumps(value, self.pickle_protocol)
Exception Type: TypeError at /admin/
Exception Value: cannot pickle '_io.BufferedReader' object
我今天也遇到了这个问题,但我还没有尝试使用其他缓存选项。
但我尝试了这个选项,它似乎工作正常。所以只需使用 image_url 而不是 image 标签,并将其句柄添加到项目 urls.py 文件中:
{% image settings.main.SiteSettings.logo_admin "height-85" alt="Home" title="Home" style="position:relative; margin-bottom:-4px" %}
在项目 urls.py 文件中:
re_path(r'^images/([^/]*)/(\d*)/([^/]*)/[^/]*$', ServeView.as_view(), name='wagtailimages_serve'),...