zoukankan      html  css  js  c++  java
  • 【Django Rest Framework】TypeError: __init__() got an unexpected keyword argument 'name'

    前端Vue问题描述:
      通过面包屑导航,无法获取导航分类对应商品列表

    后端问题描述:
    # 报错提示
    File "D:Envsvueshoplibsite-packagesdjango_filtersfilterset.py", line 258, in form Form = self.get_form_class() File "D:Envsvueshoplibsite-packagesdjango_filtersfilterset.py", line 250, in get_form_class for name, filter_ in self.filters.items()]) File "D:Envsvueshoplibsite-packagesdjango_filtersfilterset.py", line 250, in <listcomp> for name, filter_ in self.filters.items()]) File "D:Envsvueshoplibsite-packagesdjango_filtersfilters.py", line 140, in field self._field = self.field_class(label=self.label, **field_kwargs) File "D:Envsvueshoplibsite-packagesdjangoformsfields.py", line 329, in __init__ super().__init__(max_value=max_value, min_value=min_value, **kwargs) File "D:Envsvueshoplibsite-packagesdjangoformsfields.py", line 253, in __init__ super().__init__(**kwargs) TypeError: __init__() got an unexpected keyword argument 'name'

    因为报错内容中多次提到了django_filters,所以主动去filter文件中寻找name
      pricemin = django_filters.NumberFilter(name='shop_price', help_text="最低价格", lookup_expr='gte')

    后经百度查找得知,Django2版本之后,这里用field_name 代替了 name
      pricemin = django_filters.NumberFilter(field_name ='shop_price', help_text="最低价格", lookup_expr='gte')

    至此问题解决!

      


  • 相关阅读:
    AutoMapper 使用实践
    项目重构之路
    Xamarin对Visual Studio用户免费 Xamarin SDK将开源
    php的文件上传及下载,附带显示文件及目录
    SMARTY静态缓存
    SMARTY的简单实例写法
    SMARTY的知识
    wampserver的使用配置
    php权限管理
    phpcms企业站的一些知识
  • 原文地址:https://www.cnblogs.com/bk770466199/p/12686599.html
Copyright © 2011-2022 走看看