使用drf ysag记录django rest framewrok会生成“加载api定义失败”错误

yizd12fk  于 2021-09-08  发布在  Java
关注(0)|答案(0)|浏览(303)

我正在尝试记录我的django rest框架api,下面是输入链接描述文档。
我首先看到一些错误:pycharm在schema_viw.with_ui(..)上说“未解析的属性引用”with_ui'for class'type'”。下面是代码。

  1. from django.contrib import admin
  2. from django.urls import path , include
  3. from django.conf import settings
  4. from django.conf.urls.static import static
  5. from rest_framework import permissions
  6. from drf_yasg.views import get_schema_view
  7. from drf_yasg import openapi
  8. from rest_framework_swagger.views import get_swagger_view
  9. schema_view = get_schema_view(
  10. openapi.Info(
  11. title="Snippets API",
  12. default_version='v1',
  13. description="Test description",
  14. terms_of_service="https://www.google.com/policies/terms/",
  15. contact=openapi.Contact(email="contact@snippets.local"),
  16. license=openapi.License(name="BSD License"),
  17. ),
  18. public=True,
  19. permission_classes=(permissions.AllowAny,),
  20. )
  21. urlpatterns = [
  22. path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
  23. path('auth/', include('user_auth.urls')),
  24. path('api/', include('data_table.urls')),
  25. ] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)

第二:我什么时候去http://127.0.0.1:8000/swagger/ 我看到加载api定义失败错误。附加的图片显示

确切的错误。我怎样才能解决这个错误。
以下是我的设置:

  1. INSTALLED_APPS = [
  2. 'django.contrib.admin' ,
  3. 'django.contrib.auth' ,
  4. 'django.contrib.contenttypes' ,
  5. 'django.contrib.sessions' ,
  6. 'django.contrib.messages' ,
  7. 'django.contrib.staticfiles' ,
  8. 'drf_yasg',
  9. 'user_auth.apps.UserAuthConfig' ,
  10. 'rest_framework_swagger',
  11. 'rest_framework',
  12. 'django_filters' ,
  13. 'data_table',
  14. 'rest_framework_simplejwt.token_blacklist',
  15. 'corsheaders',
  16. ]
  17. REST_FRAMEWORK = {
  18. # 'DEFAULT_PERMISSION_CLASSES': [
  19. # 'rest_framework.permissions.IsAuthenticated',
  20. # ],
  21. 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
  22. 'NON_FIELD_ERRORS_KEY' : 'error' ,
  23. # 'DEFAULT_AUTHENTICATION_CLASSES' : (
  24. # 'rest_framework_simplejwt.authentication.JWTAuthentication' ,
  25. # )

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题