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

相关推荐
你的人类朋友4 小时前
说说签名与验签
后端
databook5 小时前
Manim实现脉冲闪烁特效
后端·python·动效
程序设计实验室5 小时前
2025年了,在 Django 之外,Python Web 框架还能怎么选?
python
倔强青铜三7 小时前
苦练Python第46天:文件写入与上下文管理器
人工智能·python·面试
canonical_entropy8 小时前
AI时代,我们还需要低代码吗?—— 一场关于模型、演化与软件未来的深度问答
后端·低代码·aigc
颜如玉9 小时前
HikariCP:Dead code elimination优化
后端·性能优化·源码
考虑考虑9 小时前
Jpa使用union all
java·spring boot·后端
用户25191624271110 小时前
Python之语言特点
python
bobz96510 小时前
virtio vs vfio
后端
刘立军10 小时前
使用pyHugeGraph查询HugeGraph图数据
python·graphql