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

相关推荐
金融小师妹5 小时前
多因子智能推演:油价回落6%与黄金震荡上行的关联解析——AI预测框架
大数据·python·深度学习
mldong6 小时前
工作流引擎的灵魂:状态机与 submitType
后端
BUG研究员_7 小时前
Runnable与LCEL
开发语言·人工智能·python
老马聊技术7 小时前
Pytorch深度学习环境配置与测试
人工智能·pytorch·python
朦胧之8 小时前
Go 基础
后端·go
lun8 小时前
Agent 工具调用成长史:理清楚 Function Calling、MCP、CLI 的关系
后端
Python私教8 小时前
Codex 自动写 Commit 够安全吗?一套证据化 Git 提交流程
人工智能·git·后端
Python私教8 小时前
AI Agent 上生产要不要开写权限?我把执行链拆成 4 道闸门
人工智能·后端·python
天才测试猿8 小时前
软件测试知识总结(基础篇)
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例