在使用 Django2.0 版本的 Django Rest Framwork 时,Django DeBug 报错

django-filter: TypeError at *** __init__() got an unexpected keyword argument 'name'

百度无效,于是查阅官方文档。

在 官方文档  中,是这样写的

To alter strictness behavior, the appropriate view code should be overridden. More details will be provided in future docs.

Filter.name renamed to Filter.field_name (#792)

The filter name has been renamed to field_name as a way to disambiguate the filter’s attribute name on its FilterSet class from the field_name used for filtering purposes.

所以我们代码中的 name 要改为 field_name:

    price_min = django_filters.NumberFilter(name='shop_price', lookup_expr='gte')
    price_max = django_filters.NumberFilter(name='shop_price', lookup_expr='lte')
    price_min = django_filters.NumberFilter(field_name='shop_price', lookup_expr='gte')
    price_max = django_filters.NumberFilter(field_name='shop_price', lookup_expr='lte')

再调试一下即可成功

小结:对于部分百度不到的错误,不要害怕看官方文档,官方文档往往是最权威的。

Django2.0——django-filter: TypeError at *** __init__() got an unexpected keyword argument 'name'的更多相关文章

  1. TypeError: __init__() got an unexpected keyword argument 't_command'

    python  .\manage.py migrate 报错如下 λ python .\manage.py migrateTraceback (most recent call last): File ...

  2. 关于Jupyter Notebook无法自动补全(Autocompletion),报错TypeError: __init__() got an unexpected keyword argument 'column' 的解决方案

    关于Jupyter Notebook无法自动补全(Autocompletion),报错TypeError: __init__() got an unexpected keyword argument ...

  3. TypeError: __init__() got an unexpected keyword argument 'serialized_options'

    问题描述: TypeError: __init__() got an unexpected keyword argument 'serialized_options' File "objec ...

  4. senlin __init__() got an unexpected keyword argument 'additional_headers'

    从senlin源码重新编译更新了服务,然后执行 senlin的 cli就遇到了错误: __init__() got an unexpected keyword argument 'additional ...

  5. django出现__init__() got an unexpected keyword argument 'mimetype‘ 问题解决

    这种问题好多新手按照djangobook学习的时候应该都遇到过,是因为这是老的django的写法,新的django已经升级改变了很多东西. 处理方法如下: I think you are not us ...

  6. Django-filter报错:__init__() got an unexpected keyword argument 'name'

    原因是 自从 django-filter2.0之后 将Filter的name字段 更名为 field_name 所以需要这样写: class GoodsFilter(filters.FilterSet ...

  7. kivy __init__() got an unexpected keyword argument '__no_builder' Kivy

    from kivy.lang.builder import Builder from kivy.app import App, runTouchApp from kivy.uix.boxlayout ...

  8. ypeError: __init__() got an unexpected keyword argument 'shape'

    采用TensorFlow支持通过tf.Graph函数来生成新的向量图,代码如下: import tensorflow as tf g1 = tf.Graph() with g1.as_default( ...

  9. Django TypeError: render() got an unexpected keyword argument 'renderer'

    场景: Xadmin添加plugin 来源: 1. xadmin与DjangoUeditor的安装 (第3.3章节) 2. 增加富文本编辑器Ueditor (第14.7章节) 报错: Django T ...

随机推荐

  1. Java8 Optional类使用小结

    Optional类的Javadoc描述如下: 这是一个可以为null的容器对象.如果值存在则isPresent()方法会返回true,调用get()方法会返回该对象. of:  为非null的值创建一 ...

  2. Swift4 - GCD的使用

    Swift4 - GCD的使用 2018年03月30日 17:33:27 Longshihua 阅读数:1165 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csd ...

  3. UVA 11235 RMQ算法

    上次的湘潭赛的C题,用线段树敲了下还是WA,不知道为何,我已经注意了处理相同数据,然后他们当时用的RMQ. 所以学了下RMQ,感觉算法思想是一样的,RMQ用了DP或者是递推,由单个数到2^k往上推,虽 ...

  4. expdp远程导出oracle库

    1.手动在本地建目录 E:\lvchengData 2.执行命令 create or replace directory data as 'E:\lvchengData\'; 3.为本地system用 ...

  5. Postgres psql: 致命错误: 角色 "postgres" 不存在

    问题再现 当前环境: postgresql: 11.5 windows 10 企业版LTSC 64位 当运行"C:\Program Files\PostgreSQL\11\scripts\r ...

  6. IDEA--安装

    1:下载IDEA 官网:http://www.jetbrains.com/idea/download/#section=windows(选择下载.zip) 2:解压 3:破解: 1)在C:\Windo ...

  7. blueimp,预览遮罩范围控制

    blueimg gallery github地址:https://github.com/blueimp/Gallery/blob/master/README.md 使用前提,引用css和js < ...

  8. (转)ERROR : The processing instruction target matching "[xX][mM][lL]" is not allowed.

    现象:ERROR   : The processing instruction target matching "[xX][mM][lL]" is not allowed. 异常解 ...

  9. 4)栈和队列-->受限线性表

    栈和队列叫  受限线性表  只不过他们插入和删除的位置  相对于之前的线性表有了限制   所以叫受限线性表 1)栈-->就是先进后出 2)队列-->先进先出 3)循环链表框图: 4)队列

  10. python学习笔记-模块和包

    模块导入方法 1.import 语句 import module1[,module2[,...moduleN]] 当我们使用import语句的时候,Python解释器是怎么找到对应对文件对呢?答案是解 ...