前端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')
至此问题解决!