0

尝试根据他们的文档使用drf_yasg记录 API,但我收到此错误“AttributeError:'function' object has no attribute 'with_ui'” 这是我在 urls.py中的代码

schema_view = get_schema_view(
    openapi.Info(
        title="Blog API",
        default_version='v1',
        description="A sample API for learning DRF",
        terms_of_service="https://www.google.com/policies/terms/",
        contact=openapi.Contact(email="riajulkashem@gmail.com"),
        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('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]
4

1 回答 1

1

检查您正在导入的库,它是from drf_yasg.views import get_schema_view

于 2020-09-15T07:08:45.047 回答