Django 材料与 django 智能选择错误



>我正在一个项目中使用 django 智能选择和 django 材料,并从包含 admin\templates\material\fields\django_relatedfieldwidgetwrapper.html 的页面获取'NoneType' object is not subscriptable

{% load material_form material_form_internal material_admin i18n %}
{% admin_related_field_urls bound_field as bound_field_urls %}
<div class="related-widget-wrapper">
{% render bound_field widget=field.widget.widget %}
    {% part field label %}
    <label for="{{ bound_field.id_for_label }}" class="related-widget-label">
        <span style="margin-right:5px">{{ bound_field.label }}</span>
        {% if bound_field_urls.can_change_related %}
        <a class="related-widget-wrapper-link change-related"
           data-href-template="{{ bound_field_urls.change_related_template_url }}?{{ bound_field_urls.url_params }}"
           id="change_id_{{ bound_field.html_name }}"
           title="{% blocktrans %}Change selected {{ bound_field_urls.model }}{% endblocktrans %}">
            <i class="material-icons" style="line-height:16px;font-size:16px">create</i>
        </a>
        {% endif %}
        {% if bound_field_urls.can_add_related %}
        <a class="related-widget-wrapper-link add-related"
           href="{{ bound_field_urls.add_related_url }}?{{ bound_field_urls.url_params }}"
           id="add_id_{{ bound_field.html_name }}"
           title="{% blocktrans %}Add another {{ bound_field_urls.model }}{% endblocktrans %}">
            <i class="material-icons" style="line-height:16px;font-size:16px">add</i>
        </a>
        {% endif %}
        {% if bound_field_urls.can_delete_related %}
        <a class="related-widget-wrapper-link delete-related"
           data-href-template="{{ bound_field_urls.delete_related_template_url }}?{{ bound_field_urls.url_params }}"
           id="add_id_{{ bound_field.html_name }}"
           title="{% blocktrans %}Delete selected {{ bound_field_urls.model }}{% endblocktrans %}">
            <i class="material-icons" style="line-height:16px;font-size:16px">remove</i>
        </a>
        {% endif %}
    </label>
    {% endpart %}
    {% part field help_text %}{% endpart%}
{% endrender %}
</div>

追踪:

...
File "C:libsite-packagesdjangotemplatelibrary.py" in render
  203.         output = self.func(*resolved_args, **resolved_kwargs)
File "C:libsite-packagesmaterialadmintemplatetagsmaterial_admin.py" in admin_related_field_urls
  296.         'widget': rel_widget.widget.render(bound_field.name, bound_field.value()),
File "C:projectsmart_selectswidgets.py" in render
  138.                    "id": attrs['id'],
Exception Type: TypeError at /admin/products/product/add/
Exception Value: 'NoneType' object is not subscriptable

有什么办法可以解决这个问题。提前谢谢。

您的代码中有一个错误,在第 smart_selectswidgets.py 中的 #138 行中:

File "C:projectsmart_selectswidgets.py" in render
  138.                    "id": attrs['id'],

(局部变量attrs不是字典。None

相关内容

  • 没有找到相关文章

最新更新