首页 > 解决方案 > 谷歌分析小部件的问题

问题描述

Google 分析小部件在管理页面中如下所示:

当我按下消息时,出现此错误:

错误在文件“venv/lib/site-packages/django/forms/boundfield.py”中,在以下函数中:

def as_widget(self, widget=None, attrs=None, only_initial=False):
    """
    Render the field by rendering the passed widget, adding any HTML
    attributes passed as attrs. If a widget isn't specified, use the
    field's default widget.
    """
    widget = widget or self.field.widget
    if self.field.localize:
        widget.is_localized = True
    attrs = attrs or {}
    attrs = self.build_widget_attrs(attrs, widget)
    if self.auto_id and 'id' not in widget.attrs:
        attrs.setdefault('id', self.html_initial_id if only_initial else self.auto_id)
    return widget.render(
        name=self.html_initial_name if only_initial else self.html_name,
        value=self.value(),
        attrs=attrs,
        renderer=self.form.renderer,
    )

其中小部件可以是 TextInput 或 Textarea :

from django.forms.widgets import Textarea, TextInput

然而,在文件“venv/lib/site-packages/django/forms/widgets.py”中,小部件类包含这个渲染函数,其中包含渲染器作为参数:

def render(self, name, value, attrs=None, renderer=None):
    """Render the widget as an HTML string."""
    context = self.get_context(name, value, attrs)
    return self._render(self.template_name, context, renderer)

谁能帮我这个?

标签: pythondjangogoogle-analytics-apidjango-jet

解决方案


推荐阅读