Skip to content

Swagger Docs Step

冒菜略寡味 edited this page May 9, 2018 · 2 revisions

Swagger文档化

1. 安装rest swagger

pipenv install django-rest-swagger==2.2.0

2. 添加已安装应用

accountbook/settings.py文件中添加如下:

INSTALLED_APPS = (
    ...
    'rest_framework_swagger',
)

3. 添加路由

from django.urls import path
from rest_framework_swagger.views import get_swagger_view

schema_view = get_swagger_view(title='Accountbook API')

urlpatterns = [
    path('docs/', schema_view)
]

访问http://127.0.0.1:8000/docs/查看swagger文档;

4. 登录登出

默认不设置,点击登录会调转到错误的登录URL上,故这里复用RDF中的登录登出, 设置accountbook/settings.py文件,添加如下:

LOGIN_URL = 'rest_framework:login'
LOGOUT_URL = 'rest_framework:logout'

即可正常登录登出,并获得发送请求的权限;

昨日擔當 昨日敢想

昨日轉眼 就跌撞

夏時夢長 秋時晝短

清冽途上 不遠望

Clone this wiki locally