【问题描述】
今天在搭建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',