1.reset_framework
1.1安装rest_framework
1.2使用rest_framework
在django框架中setting文件中注册rest_framework
INSTALLED_APPS = ['rest_framework', ]
2.reset_framework+swagger
2.1.安装drf_yasg
2.2.在django框架中setting文件中注册drf_yasg
INSTALLED_APPS = ['drf_yasg', ]
2.3.在setting文件中新增如下配置
TEMPLATES = [{'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': [# os.path.join(BASE_DIR, 'templates'),# os.path.join(BASE_DIR, 'drf-yasg', 'templates'),# os.path.join(BASE_DIR, 'templates')],'APP_DIRS': True,'OPTIONS': {'context_processors': ['django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',],},},
]
2.4在对应url中配置swagger
from drf_yasg.views import get_schema_view
from drf_yasg import openapischema_view = get_schema_view(openapi.Info(title="API接口文档平台", # 必传default_version='v1', # 必传description="这是一个接口文档",license=openapi.License(name="BSD License"),),public=True,# permission_classes=(permissions.AllowAny,), # 权限类
)urlpatterns = [path('admin/',admin.site.urls),path('api-auth/', include('rest_framework.urls')),path('newProjectApp/',include('newProjectApp.urls')),# 以下是swagger路由配置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'),]
2.5启动django服务
3.reset_framework+swagger+Apifox
3.1安装apifox扩展件或者下载对应的apifox桌面端
tips:1.需要手动刷新扩展件之后 或者手动刷新当前访问apifox网页端的页面