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',
        )

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

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

  • 相关阅读:
    中綴表達式求值的兩種方法
    两次bfs求树的直径的正确性
    感染linux脚本程序技术
    C# 动态代码执行
    中秋写了个狼吃羊的智力游戏
    做一个让人喜欢的人
    MySQL数据库安全配置指南
    用 VS 2005 生成 .NET 1.1 程序
    防止入侵和攻击的主要技术措施
    .NETZ 原理分析
  • 原文地址:https://www.cnblogs.com/shiyixirui/p/14495189.html
Copyright © 2011-2022 走看看