在使用 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. C++ STD Gems05

    find.find_if.find_first_of.mismatch.search.adjacent_find #include <iostream> #include <vect ...

  2. python-局域网内实现web页面用户端下载文件,easy!

    好久没有发博客了,但是也没闲着,最近疫情原因一直在家远程办公,分享一下今天的干货 先说需求:某个文件压缩之后可以供用户点击下载 没想到特别好的办法,在网上搜索大多都是通过socket实现的,然后我这个 ...

  3. Session.Abandon与Session.Clear之间的区别

    Session.Clear()就是把Session对象中的所有项目都删除了,Session对象里面什么都没有.但是Session对象还保留. Session.Abandon()就是把当前Session ...

  4. spring boot 异常(exception)处理

    Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...

  5. web嵌入到原生的app里需要注意的事项

    1.https://www.cnblogs.com/shimily/articles/7943370.html 2.https://www.cnblogs.com/stoneniqiu/p/60771 ...

  6. SAP_FICO常用事务代码

    1.会计科目维护: FS00:总账科目主记录维护 FSP0:科目表中总账科目主记录维护 FSS0:公司代码中总账科目主记录维护 2.会计凭证创建 FB01:创建凭证 F-02:总账凭证创建(在FB01 ...

  7. Java底层魔术类Unsafe用法简述

    1 引子 Java中没有指针,不能直接对内存地址的变量进行控制,但Java提供了一个特殊的类Unsafe工具类来间接实现.Unsafe主要提供一些用于执行低级别.不安全操作的方法,如直接访问系统内存资 ...

  8. c++ 字母排序

    char a[123] = {'Z', 's', 'p', 'l', 'j', 'r', 'q', 'v', 'n', 'm', 'C', 'F', 'D', 'B', 'A', '2', '0', ...

  9. 连接mysql的各种方式

    mysql连接操作是客户端进程与mysql数据库实例进程进行通信.从程序设计角度来说,属于进程通信,常用进程通信包括: 管道.Tcp/Ip 套接字.UNIX域套接字. 1.TCP/IP (1)使用最多 ...

  10. 112.限制请求的method装饰器

    客户端与服务器之间最常用的两种请求方式: 1. GET请求一般是用来向服务器索取数据,但不会向服务器提交数据,不会对服务器的状态进行更改. 2.POST请求一般是用来向服务器提交数据,会对服务器的状态 ...