axnsan12 / drf-yasg

Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.
https://drf-yasg.readthedocs.io/en/stable/
Other
3.4k stars 435 forks source link

A quest occur after i custom a RestResponsePagination #623

Open shyzz opened 4 years ago

shyzz commented 4 years ago

hi developer, i meet a problem. for some reason, i overwriter DjangoRestResponsePagination for realizing a custom response 。

image this class path is project_path/libs/pagination then i add this class for django settings file. `REST_FRAMEWORK = { "DEFAULT_SCHEMA_CLASS": "rest_framework.schemas.coreapi.AutoSchema",

"DEFAULT_RENDERER_CLASSES": ["djangorestframework_camel_case.render.CamelCaseJSONRenderer"],

# "DEFAULT_PERMISSION_CLASSES": [
#    "rest_framework.permissions.IsAuthenticated"
# ],
"EXCEPTION_HANDLER": "libs.exception.exception_handler",
# 分页器设置
"DEFAULT_PAGINATION_CLASS": "libs.pagination.PageNumberPagination",
"PAGE_SIZE": 50

}

SWAGGER_SETTINGS = { "DEFAULT_INFO": "config.urls.info", "DEFAULT_PAGINATOR_INSPECTORS": [ "libs.pagination.RestResponsePagination", "drf_yasg.inspectors.CoreAPICompatInspector", ], } last, i try to import my custom paginator_inspector in python shell from libs.pagination import RestResponsePagination ` but the error is occuring. ImportError: Could not import 'libs.pagination.RestResponsePagination' for API setting 'DEFAULT_PAGINATOR_INSPECTORS'. ImportError: Module "libs.pagination" does not define a "RestResponsePagination" attribute/class.

my question is why occur this error.

i try to some method,when i notes "from drf_yasg.inspectors import DjangoRestResponsePagination", the question is solved。 thanks reply

axnsan12 commented 3 years ago

I imagine this has to do with some cyclic imports. A stack trace would be helpful.