coreapi接口文档
pip install coreapi
pip install markdown
REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}
from rest_framework.documentation import include_docs_urls
urlpatterns = [
...
path('docs/', include_docs_urls(title='测试平台接口文档', description='这是一个接口测试平台'))
]
http://127.0.0.1:8000/docs/
swagger接口文档
pip install drf-yasg
INSTALLED_APPS = ['drf_yasg']
from django.urls import path, re_path
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
schema_view = get_schema_view(
openapi.Info(
title="Lemon API接口文档平台",
default_version='v1',
description="这是一个美轮美奂的接口文档",
terms_of_service="http://api.keyou.site",
contact=openapi.Contact(email="keyou100@qq.com"),
license=openapi.License(name="BSD License"),
),
public=True,
)
urlpatterns = [
re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
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'),
]
http://127.0.0.1:8000/swagger.json
http://127.0.0.1:8000/swagger
http://127.0.0.1:8000/redoc