【Python】AttributeError: 'AutoSchema' object has no attribute 'get_link'

【问题描述】

       今天在搭建django-rest-swagger的时候出现了如下错误:

Traceback (most recent call last):
  File "D:\anaconda\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "D:\anaconda\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "D:\anaconda\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\anaconda\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "D:\anaconda\lib\site-packages\django\views\generic\base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "D:\anaconda\lib\site-packages\rest_framework\views.py", line 505, in dispatch
    response = self.handle_exception(exc)
  File "D:\anaconda\lib\site-packages\rest_framework\views.py", line 465, in handle_exception
    self.raise_uncaught_exception(exc)
  File "D:\anaconda\lib\site-packages\rest_framework\views.py", line 476, in raise_uncaught_exception
    raise exc
  File "D:\anaconda\lib\site-packages\rest_framework\views.py", line 502, in dispatch
    response = handler(request, *args, **kwargs)
  File "D:\pycharmProjects\testDjango\myapp\views.py", line 99, in get
    schema = generator.get_schema(request=request)
  File "D:\anaconda\lib\site-packages\rest_framework\schemas\coreapi.py", line 156, in get_schema
    links = self.get_links(None if public else request)
  File "D:\pycharmProjects\testDjango\myapp\views.py", line 73, in get_links
    link = view.schema.get_link(path, method, base_url=self.url)
AttributeError: 'AutoSchema' object has no attribute 'get_link'
[13/Apr/2020 16:39:30] "GET /docs/ HTTP/1.1" 500 17218

【解决办法】

       需要在配置文件settings.py中指定schema_class的配置:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

象在舞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值