错误消息“必须安装 `coreapi` 以支持架构”
Error message "`coreapi` must be installed for schema support"
我正在尝试使用 drf_yasg
生成 Swagger 文档,它工作正常,但现在不行了。
它给我一个错误,我找不到解决方案。
为什么会出现此错误?
Environment:
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.
这是一个愚蠢的错误。我创建了一个目录来存储额外的文件,drf_yasg
正在将其视为一个应用程序并试图为其生成 URL。
我从该目录中删除了 __init__.py
文件并且它起作用了。
我正在尝试使用 drf_yasg
生成 Swagger 文档,它工作正常,但现在不行了。
它给我一个错误,我找不到解决方案。
为什么会出现此错误?
Environment:
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.
这是一个愚蠢的错误。我创建了一个目录来存储额外的文件,drf_yasg
正在将其视为一个应用程序并试图为其生成 URL。
我从该目录中删除了 __init__.py
文件并且它起作用了。