django REST framework 3.10.3 访问 /api/docs/ 报错 'AutoSchema' object has no attribute 'g

2023-02-18 10:54:49 浏览数 (1)

环境

  • python 3.6.8
  • django 2.2.6
  • django rest framework  3.10.3

报错

访问 django rest framework  api 文档( /api/docs/ )时报错:

AttributeError: 'AutoSchema' object has no attribute 'get_link'

解决办法

settings.py 的 REST_FRAMEWORK 配置增加:

'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.AutoSchema',

代码语言:javascript复制
# drf 配置
REST_FRAMEWORK = {

    # AttributeError: 'AutoSchema' object has no attribute 'get_link'
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.AutoSchema'
}

参考文档

  • https://github.com/encode/django-rest-framework/issues/6809
  • https://www.cnblogs.com/iiiiiher/p/11248456.html
  • https://stackoverflow.com/questions/57123611/why-swagger-raises-unclear-error-django

0 人点赞