我正在尝试将https://github.com/axnsan12/drf-yasg这个库添加到我们的 django 应用程序并得到以下错误。
permission_classes=(permissions.AllowAny,),
File "/env/lib/python3.7/site-packages/drf_yasg/views.py", line 67, in get_schema_view
_generator_class = generator_class or swagger_settings.DEFAULT_GENERATOR_CLASS
File "env/lib/python3.7/site-packages/drf_yasg/app_settings.py", line 122, in __getattr__
val = perform_import(val, attr)
File "env/lib/python3.7/site-packages/rest_framework/settings.py", line 166, in perform_import
return import_from_string(val, setting_name)
File "env/lib/python3.7/site-packages/rest_framework/settings.py", line 180, in import_from_string
raise ImportError(msg)
ImportError: Could not import 'drf_yasg.generators.OpenAPISchemaGenerator' for API setting 'DEFAULT_GENERATOR_CLASS'. ImportError: cannot import name 'URLPattern' from 'rest_framework.compat' (env/lib/python3.7/site-packages/rest_framework/compat.py).
经过一些研究,我发现有些人建议安装这个包来解决这个问题
pip3 install packaging
但这没有任何区别。还有其他可用于 django rest api 的好的 api 文档库吗?