zoukankan      html  css  js  c++  java
  • 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',
        )

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

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

  • 相关阅读:
    老了老了呜呜呜呜
    我们的焦点在哪里
    visual studio 2010
    饥饿游戏2 影评
    两个极端
    关于怀旧
    进程 线程 碎角料
    拥塞控制
    [zz] 几种类间关系:继承、实现、依赖、关联、聚合、组合及UML实现图
    Markdown 的使用
  • 原文地址:https://www.cnblogs.com/shiyixirui/p/14495189.html
Copyright © 2011-2022 走看看