django(REST_FRAMEWORK)+swagger+Apifox 集成

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文件中新增如下配置

python 复制代码
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

python 复制代码
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

schema_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网页端的页面

相关推荐
昵称为空C4 分钟前
kafka的替代品redpanda部署与SpringBoot集成使用案例
spring boot·后端·kafka
天下无敌笨笨熊31 分钟前
ES作为向量库研究
大数据·python·elasticsearch
数据知道40 分钟前
FastAPI项目:从零到一搭建一个网站导航系统
python·mysql·fastapi·python web·python项目
q***09801 小时前
Spring Boot 2.7.x 至 2.7.18 及更旧的版本,漏洞说明
java·spring boot·后端
程序员爱钓鱼1 小时前
Python 编程实战 · 进阶与职业发展:数据分析与 AI(Pandas、NumPy、Scikit-learn)
后端·python·trae
软件开发技术深度爱好者1 小时前
Python库/包/模块管理工具
开发语言·python
程序员爱钓鱼1 小时前
Python 编程实战 · 进阶与职业发展:Web 全栈(Django / FastAPI)
后端·python·trae
IT_陈寒2 小时前
90%的Python开发者不知道:这5个内置函数让你的代码效率提升300%
前端·人工智能·后端
郝学胜-神的一滴2 小时前
Python中一切皆对象:深入理解Python的对象模型
开发语言·python·程序人生·个人开发
我的虾分发2 小时前
虾分发平台提供多种价格套餐
后端