drf_yasg AttributeError:“函数”对象没有属性“ with_ui”

时间:2020-09-05 18:36:04

标签: python django django-rest-framework drf-yasg

尝试根据drf_yasg的文档记录API,但出现此错误 “ AttributeError:'function'对象没有属性'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'),
]

1 个答案:

答案 0 :(得分:0)

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