-1

我正在尝试使用 生成 swagger 文档drf_yasg,它工作正常,但现在不行。它给了我错误,我找不到解决方案。

知道为什么我会收到此错误吗?



Request Method: GET
Request URL: http://0.0.0.0:8007/doc/

Django Version: 3.2.4
Python Version: 3.9.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.staticfiles',
 'rest_framework',
 'drf_yasg',
 'promotions',
 'vendor',
 'settings']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'includes.common.middlewares.identity.IdentityMiddleware',
 'includes.common.middlewares.timezone.TimezoneMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/drf_yasg/views.py", line 92, in get
    generator = self.generator_class(info, version, url, patterns=[])
  File "/usr/local/lib/python3.9/site-packages/drf_yasg/generators.py", line 183, in __init__
    self._gen = SchemaGenerator(info.title, url, info.get('description', ''), patterns, urlconf)
  File "/usr/local/lib/python3.9/site-packages/rest_framework/schemas/coreapi.py", line 120, in __init__
    assert coreapi, '`coreapi` must be installed for schema support.'

Exception Type: AssertionError at /doc/
Exception Value: `coreapi` must be installed for schema support.```
4

1 回答 1

0

这是一个愚蠢的错误。我创建了一个目录来存储额外的文件,并将drf_yasg其视为一个应用程序,并试图为其生成 URL。我__init__.py从该目录中删除了文件并且它有效。

于 2021-06-29T05:25:07.333 回答