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

相关推荐
适应规律6 分钟前
【无标题】
人工智能·python·算法
XLYcmy14 分钟前
全链路验证测试系统:一个针对智能代理(Agent)系统全链路能力的自动化验证脚本
分布式·python·http·网络安全·ai·llm·agent
有味道的男人24 分钟前
电商效率翻倍:京东全量商品信息抓取
python
原来是猿1 小时前
博客系统自动化测试实战总结
python
我是一颗柠檬1 小时前
【MySQL全面教学】MySQL性能优化实战Day13(2026年)
数据库·后端·sql·mysql·性能优化·database
小江的记录本1 小时前
【JVM虚拟机】JVM调优:常用JVM参数、调优核心指标、OOM排查、GC日志分析、Arthas工具使用(附《思维导图》+《面试高频考点清单》)
java·jvm·spring boot·后端·python·spring·面试
大数据魔法师1 小时前
Streamlit(十三)- API 参考文档(六)- 媒体展示组件
python·web
爱写代码的倒霉蛋1 小时前
Hello-Agents的第一个练习-5分钟实现一个智能体(实现详解)
python
程序员cxuan1 小时前
我花了两天时间,终于把 Codex 额度掉太快的问题整明白了!!
人工智能·后端·程序员
IT_陈寒1 小时前
Vue这个动态响应坑把我整不会了
前端·人工智能·后端