• Djangorestframework 记录一个报错 -- rest_framework.authentication.ToKenAuthentication


    今天在使用 Djangorestframework 这个框架时,发生报错:

    ImportError: Could not import 'rest_framework.authentication.ToKenAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. 
    ImportError: Module "rest_framework.authentication" does not define a "ToKenAuthentication" attribute/class.

    看报错信息就知道,是 settings 设置的问题,我是这样写的

    'DEFAULT_AUTHENTICATION_CLASSES': [
            # 认证
            'rest_framework.authentication.BasicAuthentication',
            'rest_framework.authentication.SessionAuthentication',
            'rest_framework.authentication.ToKenAuthentication',
        ]

    没毛病啊,是单词写错了? 仔细看了好久,没发现什么问题,然后就开启百度模式,搜了好久,搜了很多方法,都没用。

    凭借多年以来处理问题的方法,遇到事情不要慌,抽根烟冷静下(此处并非教唆大家去抽烟,大家可以忽略这一句),抽了根烟,喝了杯茶,然后脑子突然灵光一现,发现了问题

    以下是我改正后的代码

    'DEFAULT_AUTHENTICATION_CLASSES': (
            'rest_framework.authentication.BasicAuthentication',
            'rest_framework.authentication.SessionAuthentication',
            'rest_framework.authentication.TokenAuthentication',
        )

    改完后,一运行,哎呀,这问题就解决了  ......

    原来这个地方应该元祖来写配置,不能用列表。

  • 相关阅读:
    八、总结
    第5章、Kafka监控
    十一、总结
    十、图形化的客户端和监控工具
    九、zookeeper四字监控命令
    八、zookeeper 开源客户端curator介绍
    七、Zookeeper原理
    六、zookeeper 事件监听机制
    五、zookeeper的javaApi
    四、zookeeper的Acl权限控制
  • 原文地址:https://www.cnblogs.com/shiyixirui/p/14495189.html
Copyright © 2020-2023  润新知