我正在尝试记录我的django rest框架api,下面是输入链接描述文档。
我首先看到一些错误:pycharm在schema_viw.with_ui(..)上说“未解析的属性引用”with_ui'for class'type'”。下面是代码。
from django.contrib import admin
from django.urls import path , include
from django.conf import settings
from django.conf.urls.static import static
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from rest_framework_swagger.views import get_swagger_view
schema_view = get_schema_view(
openapi.Info(
title="Snippets API",
default_version='v1',
description="Test description",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="contact@snippets.local"),
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)
urlpatterns = [
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('auth/', include('user_auth.urls')),
path('api/', include('data_table.urls')),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
第二:我什么时候去http://127.0.0.1:8000/swagger/ 我看到加载api定义失败错误。附加的图片显示
确切的错误。我怎样才能解决这个错误。
以下是我的设置:
INSTALLED_APPS = [
'django.contrib.admin' ,
'django.contrib.auth' ,
'django.contrib.contenttypes' ,
'django.contrib.sessions' ,
'django.contrib.messages' ,
'django.contrib.staticfiles' ,
'drf_yasg',
'user_auth.apps.UserAuthConfig' ,
'rest_framework_swagger',
'rest_framework',
'django_filters' ,
'data_table',
'rest_framework_simplejwt.token_blacklist',
'corsheaders',
]
REST_FRAMEWORK = {
# 'DEFAULT_PERMISSION_CLASSES': [
# 'rest_framework.permissions.IsAuthenticated',
# ],
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
'NON_FIELD_ERRORS_KEY' : 'error' ,
# 'DEFAULT_AUTHENTICATION_CLASSES' : (
# 'rest_framework_simplejwt.authentication.JWTAuthentication' ,
# )
暂无答案!
目前还没有任何答案,快来回答吧!