Django/Wagtail:当我刷新我的文章博客页面时,/blog/article-blog-page/ 处出现 InvalidFilterSpecError
Django/Wagtail : InvalidFilterSpecError at /blog/article-blog-page/ when i refresh my Article Blog Page
在按照 Wagtail CMS: How to subclass Wagtail Pages 的教程进行操作时,我在刷新文章博客页面时遇到了错误。我正在使用调试工具栏 3.2.2、Python 3.9.6、Wagtail 核心 2.14.1、Taggit 1.5.1 和 Django 扩展 3.1.3。
错误代码:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/blog/article-blog-page/
Django Version: 3.2.7
Python Version: 3.9.6
Installed Applications:
['home',
'search',
'flex',
'streams',
'site_settings',
'subscribers',
'blog',
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.contrib.settings',
'wagtail.contrib.routable_page',
'wagtail.contrib.sitemaps',
'wagtail.contrib.modeladmin',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
'wagtail.snippets',
'wagtail.documents',
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail.core',
'modelcluster',
'taggit',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sitemaps',
'debug_toolbar',
'django_extensions']
Installed Middleware:
['django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'wagtail.contrib.redirects.middleware.RedirectMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware']
Template error:
In template C:\Users\pedro.garcia\website\mysite\mysite\templates\base.html, error at line 35
construct() missing 1 required positional argument: 'size'
25 : {% block extra_css %}
26 : {# Override this in templates to add extra stylesheets #}
27 : {% endblock %}
28 : </head>
29 :
30 : <body class="{% block body_class %}{% endblock %}">
31 : {% wagtailuserbar %}
32 : <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
33 : <div class="container-fluid">
34 : <a class="navbar-brand" href="#">Sesacre</a>
35 : <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarColor02" aria-controls="navbarCo lor02" aria-expanded="false" aria-label="Toggle navigat ion">
36 : <span class="navbar-toggler-icon"></span>
37 : </button>
38 :
39 : <div class="collapse navbar-collapse" id="navbarColor02">
40 :
41 : <ul class="navbar-nav me-auto">
42 : <li class="nav-item">
43 : <a class="nav-link active" href="/">início
44 : <span class="visually-hidden">(current)</span>
45 : </a>
Traceback (most recent call last):
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\image_operations.py", line 15, in __init__
inspect.getcallargs(self.construct, *args)
File "c:\users\pedro.garcia\appdata\local\programs\python\python39\lib\inspect.py", line 1411, in getcallargs
_missing_arguments(f_name, req, True, arg2value)
File "c:\users\pedro.garcia\appdata\local\programs\python\python39\lib\inspect.py", line 1340, in _missing_arguments
raise TypeError("%s() missing %i required %s argument%s: %s" %
During handling of the above exception (construct() missing 1 required positional argument: 'size'), another exception occurred:
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\core\handlers\base.py", line 204, in _get_response
response = response.render()
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\response.py", line 105, in render
self.content = self.rendered_content
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\response.py", line 83, in rendered_content
return template.render(context, self._request)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 170, in render
return self._render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\test\utils.py", line 100, in instrumented_test_render
return self.nodelist.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 938, in render
bit = node.render_annotated(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 905, in render_annotated
return self.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\test\utils.py", line 100, in instrumented_test_render
return self.nodelist.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 938, in render
bit = node.render_annotated(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 905, in render_annotated
return self.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 938, in render
bit = node.render_annotated(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 905, in render_annotated
return self.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\defaulttags.py", line 312, in render
return nodelist.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 938, in render
bit = node.render_annotated(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 905, in render_annotated
return self.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\templatetags\wagtailimages_tags.py", line 107, in render
rendition = get_rendition_or_not_found(image, self.filter)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\shortcuts.py", line 13, in get_rendition_or_not_found
return image.get_rendition(specs)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\models.py", line 281, in get_rendition
cache_key = filter.get_cache_key(self)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\models.py", line 480, in get_cache_key
for operation in self.operations:
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\models.py", line 410, in operations
operations.append(op_class(*op_spec_parts))
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\image_operations.py", line 17, in __init__
raise InvalidFilterSpecError(e)
Exception Type: InvalidFilterSpecError at /blog/article-blog-page/
Exception Value: construct() missing 1 required positional argument: 'size'
如果还有什么需要补充的,请写下来
编辑 1:我的 article_blog_page.html:
{% extends "base.html" %}
{% load wagtailimages_tags wagtailcore_tags %}
{% block content %}
{% image self.banner_image fill-1200x300 as banner %}
<img src="{{ banner.url }}" alt="{{ banner.alt }}" style='width: 100%; height: auto;'>
<div class="container mt-5 mb-5">
<div class="text-center">
<h1>{% if self.custom_title %}{{ self.custom_title }}{% else %}{{ self.title }}{% endif %}</h1>
{% if self.subtitle %}
{% if self.categories.count %}
<h3>{{ self.subtitle }}</h3>
{% endif %}
<div style="padding: 0 20px 20px">
{% for cat in self.categories.all %}
<a href="?category={{ cat.slug }}">
{{ cat.name }}
</a>{% if not forloop.last %}, {% endif %}
{% endfor %}
</div>
{% endif %}
<div class="d-flex justify-content-center">
{% for iter in self.blog_authors.all %}
{% image iter.author.image fill-50x50 as img %}
<div>
<div>
<img src="{{ img.url }}" class="rounded-circle" alt="{{ iter.author.name }}">
</div>
{% if iter.author.website %}
<a href="{{ iter.author.website }}">
{{ iter.author.name }}
</a>
{% else %}
{{ iter.author.name }}
{% endif %}
</div>
{% endfor %}
</div>
</div>
</div>
{% if self.intro_image %}
<div class="container">
<div class="row">
<div class="col-lg-8 offset-lg-2"
{% image self.intro_image fill 1400x400 as intro_img %}
<img src="{{ intro_img.url }}" alt="{{ intro_img.alt }}">
</div>
</div>
</div>
{% endif %}
<div class="container">
<div class="row">
<div class="col-lg-8 offset-lg-2">
{% for block in self.content %}
{% include_block block %}
{% endfor %}
</div>
</div>
</div>
{% endblock %}
{% image self.intro_image fill 1400x400 as intro_img %}
应该是
{% image self.intro_image fill-1400x400 as intro_img %}
(注意 'fill' 之后的 -
,而不是 space)
在按照 Wagtail CMS: How to subclass Wagtail Pages 的教程进行操作时,我在刷新文章博客页面时遇到了错误。我正在使用调试工具栏 3.2.2、Python 3.9.6、Wagtail 核心 2.14.1、Taggit 1.5.1 和 Django 扩展 3.1.3。
错误代码:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/blog/article-blog-page/
Django Version: 3.2.7
Python Version: 3.9.6
Installed Applications:
['home',
'search',
'flex',
'streams',
'site_settings',
'subscribers',
'blog',
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.contrib.settings',
'wagtail.contrib.routable_page',
'wagtail.contrib.sitemaps',
'wagtail.contrib.modeladmin',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
'wagtail.snippets',
'wagtail.documents',
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail.core',
'modelcluster',
'taggit',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sitemaps',
'debug_toolbar',
'django_extensions']
Installed Middleware:
['django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'wagtail.contrib.redirects.middleware.RedirectMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware']
Template error:
In template C:\Users\pedro.garcia\website\mysite\mysite\templates\base.html, error at line 35
construct() missing 1 required positional argument: 'size'
25 : {% block extra_css %}
26 : {# Override this in templates to add extra stylesheets #}
27 : {% endblock %}
28 : </head>
29 :
30 : <body class="{% block body_class %}{% endblock %}">
31 : {% wagtailuserbar %}
32 : <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
33 : <div class="container-fluid">
34 : <a class="navbar-brand" href="#">Sesacre</a>
35 : <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarColor02" aria-controls="navbarCo lor02" aria-expanded="false" aria-label="Toggle navigat ion">
36 : <span class="navbar-toggler-icon"></span>
37 : </button>
38 :
39 : <div class="collapse navbar-collapse" id="navbarColor02">
40 :
41 : <ul class="navbar-nav me-auto">
42 : <li class="nav-item">
43 : <a class="nav-link active" href="/">início
44 : <span class="visually-hidden">(current)</span>
45 : </a>
Traceback (most recent call last):
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\image_operations.py", line 15, in __init__
inspect.getcallargs(self.construct, *args)
File "c:\users\pedro.garcia\appdata\local\programs\python\python39\lib\inspect.py", line 1411, in getcallargs
_missing_arguments(f_name, req, True, arg2value)
File "c:\users\pedro.garcia\appdata\local\programs\python\python39\lib\inspect.py", line 1340, in _missing_arguments
raise TypeError("%s() missing %i required %s argument%s: %s" %
During handling of the above exception (construct() missing 1 required positional argument: 'size'), another exception occurred:
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\core\handlers\base.py", line 204, in _get_response
response = response.render()
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\response.py", line 105, in render
self.content = self.rendered_content
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\response.py", line 83, in rendered_content
return template.render(context, self._request)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 170, in render
return self._render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\test\utils.py", line 100, in instrumented_test_render
return self.nodelist.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 938, in render
bit = node.render_annotated(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 905, in render_annotated
return self.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\test\utils.py", line 100, in instrumented_test_render
return self.nodelist.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 938, in render
bit = node.render_annotated(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 905, in render_annotated
return self.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 938, in render
bit = node.render_annotated(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 905, in render_annotated
return self.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\defaulttags.py", line 312, in render
return nodelist.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 938, in render
bit = node.render_annotated(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\template\base.py", line 905, in render_annotated
return self.render(context)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\templatetags\wagtailimages_tags.py", line 107, in render
rendition = get_rendition_or_not_found(image, self.filter)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\shortcuts.py", line 13, in get_rendition_or_not_found
return image.get_rendition(specs)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\models.py", line 281, in get_rendition
cache_key = filter.get_cache_key(self)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\models.py", line 480, in get_cache_key
for operation in self.operations:
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\models.py", line 410, in operations
operations.append(op_class(*op_spec_parts))
File "C:\Users\pedro.garcia\.virtualenvs\mysite-BGHBG09T\lib\site-packages\wagtail\images\image_operations.py", line 17, in __init__
raise InvalidFilterSpecError(e)
Exception Type: InvalidFilterSpecError at /blog/article-blog-page/
Exception Value: construct() missing 1 required positional argument: 'size'
如果还有什么需要补充的,请写下来
编辑 1:我的 article_blog_page.html:
{% extends "base.html" %}
{% load wagtailimages_tags wagtailcore_tags %}
{% block content %}
{% image self.banner_image fill-1200x300 as banner %}
<img src="{{ banner.url }}" alt="{{ banner.alt }}" style='width: 100%; height: auto;'>
<div class="container mt-5 mb-5">
<div class="text-center">
<h1>{% if self.custom_title %}{{ self.custom_title }}{% else %}{{ self.title }}{% endif %}</h1>
{% if self.subtitle %}
{% if self.categories.count %}
<h3>{{ self.subtitle }}</h3>
{% endif %}
<div style="padding: 0 20px 20px">
{% for cat in self.categories.all %}
<a href="?category={{ cat.slug }}">
{{ cat.name }}
</a>{% if not forloop.last %}, {% endif %}
{% endfor %}
</div>
{% endif %}
<div class="d-flex justify-content-center">
{% for iter in self.blog_authors.all %}
{% image iter.author.image fill-50x50 as img %}
<div>
<div>
<img src="{{ img.url }}" class="rounded-circle" alt="{{ iter.author.name }}">
</div>
{% if iter.author.website %}
<a href="{{ iter.author.website }}">
{{ iter.author.name }}
</a>
{% else %}
{{ iter.author.name }}
{% endif %}
</div>
{% endfor %}
</div>
</div>
</div>
{% if self.intro_image %}
<div class="container">
<div class="row">
<div class="col-lg-8 offset-lg-2"
{% image self.intro_image fill 1400x400 as intro_img %}
<img src="{{ intro_img.url }}" alt="{{ intro_img.alt }}">
</div>
</div>
</div>
{% endif %}
<div class="container">
<div class="row">
<div class="col-lg-8 offset-lg-2">
{% for block in self.content %}
{% include_block block %}
{% endfor %}
</div>
</div>
</div>
{% endblock %}
{% image self.intro_image fill 1400x400 as intro_img %}
应该是
{% image self.intro_image fill-1400x400 as intro_img %}
(注意 'fill' 之后的 -
,而不是 space)