boundfield.py -- render() 得到了一个意外的关键字参数'renderer'



我在这里多次看到此错误,每次似乎都不同。 我正在开发一个带有传单的geodjango应用程序。自从我安装了传单以来,我收到此错误。 我在另一篇文章中骑了这个:

  • 删除了对不带渲染器参数的 Widget.render(( 方法的支持。

有什么方法可以在不必返回版本 - 2.0.8 的情况下解决此问题?

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/admin/travel/location/15493/change/
Django Version: 3.0.4
Python Version: 3.8.2
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'pages.apps.PagesConfig',
'travel.apps.TravelConfig',
'django_extensions',
'leaflet']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'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']

Template error:
In template /Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/contrib/admin/templates/admin/includes/fieldset.html, error at line 19
render() got an unexpected keyword argument 'renderer'
9 :             {% for field in line %}
10 :                 <div{% if not line.fields|length_is:'1' %} class="fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}>
11 :                     {% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}
12 :                     {% if field.is_checkbox %}
13 :                         {{ field.field }}{{ field.label_tag }}
14 :                     {% else %}
15 :                         {{ field.label_tag }}
16 :                         {% if field.is_readonly %}
17 :                             <div class="readonly">{{ field.contents }}</div>
18 :                         {% else %}
19 :                              {{ field.field }} 
20 :                         {% endif %}
21 :                     {% endif %}
22 :                     {% if field.field.help_text %}
23 :                         <div class="help">{{ field.field.help_text|safe }}</div>
24 :                     {% endif %}
25 :                 </div>
26 :             {% endfor %}
27 :         </div>
28 :     {% endfor %}
29 : </fieldset>

Traceback (most recent call last):
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/core/handlers/base.py", line 145, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/core/handlers/base.py", line 143, in _get_response
response = response.render()
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/response.py", line 105, in render
self.content = self.rendered_content
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/response.py", line 83, in rendered_content
return template.render(context, self._request)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 171, in render
return self._render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/loader_tags.py", line 188, in render
return template.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 173, in render
return self._render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/defaulttags.py", line 209, in render
nodelist.append(node.render_annotated(context))
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/defaulttags.py", line 309, in render
return nodelist.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/defaulttags.py", line 309, in render
return nodelist.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 936, in render
bit = node.render_annotated(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
return self.render(context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 992, in render
return render_value_in_context(output, context)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/template/base.py", line 971, in render_value_in_context
value = str(value)
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/utils/html.py", line 373, in <lambda>
klass.__str__ = lambda self: mark_safe(klass_str(self))
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/forms/boundfield.py", line 33, in __str__
return self.as_widget()
File "/Users/marcusbey/.local/share/virtualenvs/rb-website-fKSjEdfu/lib/python3.8/site-packages/django/forms/boundfield.py", line 92, in as_widget
return widget.render(
Exception Type: TypeError at /admin/travel/location/15493/change/
Exception Value: render() got an unexpected keyword argument 'renderer'

尽管仅注释boundfield.py中的第 97 行有效,但我通过导航到调用渲染函数的文件夹解决了这个问题。例如,通过在django_markdown文件夹中widgets.py文件中添加renderer=None解决了问题。

boundfield.py

return widget.render(
name=self.html_initial_name if only_initial else self.html_name,
value=self.value(),
attrs=attrs,
#renderer=self.form.renderer,
)

widgets.py

""" Widgets for django-markdown. """
import os
from django import forms
from django.contrib.admin.widgets import AdminTextareaWidget
from django.core.files.storage import default_storage
from django.utils.safestring import mark_safe
from . import settings
from .utils import editor_js_initialization

class MarkdownWidget(forms.Textarea):
""" Widget for a textarea.
Takes two additional optional keyword arguments:
``markdown_set_name``
Name for current set. Default: value of MARKDOWN_SET_NAME setting.
``markdown_skin``
Name for current skin. Default: value of MARKDOWN_EDITOR_SKIN setting.
"""
def __init__(self, attrs=None):
super(MarkdownWidget, self).__init__(attrs)
def render(self, name, value, attrs=None, renderer=None):
""" Render widget.
:returns: A rendered HTML
"""
html = super(MarkdownWidget, self).render(name, value, attrs)
attrs = self.build_attrs(attrs)
html += editor_js_initialization("#%s" % attrs['id'])
return mark_safe(html)
class Media:
css = {
'screen': (
os.path.join('django_markdown', 'skins', settings.MARKDOWN_EDITOR_SKIN, 'style.css'),
os.path.join(settings.MARKDOWN_SET_PATH, settings.MARKDOWN_SET_NAME, 'style.css')
)
}
js = (
os.path.join('django_markdown', 'jquery.init.js'),
os.path.join('django_markdown', 'jquery.markitup.js'),
os.path.join(settings.MARKDOWN_SET_PATH, settings.MARKDOWN_SET_NAME, 'set.js')
)

class AdminMarkdownWidget(MarkdownWidget, AdminTextareaWidget):
""" Support markdown widget in Django Admin. """
pass

我之前遇到过同样的问题,但没有找到任何修复方法,但我删除了 boundfield.py 文件中的"渲染器"行,该文件将是内联 92 只是删除它。

相关内容

  • 没有找到相关文章

最新更新