0030 apidoc接口文档
2021-01-08 22:30
标签:site 插件 app 编译 nucleus word ram pat object 1 创建Django工程 1.1 安装pip,django等相关插件 1.2 创建app 1.3 创建视图 1.4 配置路由 2 安装apidoc 使用淘宝镜像安装 2.1 命令 1.2 验证命令 如果返回https://registry.npm.taobao.org,说明镜像配置成功。 2 安装apidoc 3 为视图编写注释代码 4 先在项目根目录下放一个apidoc.json文件,示例如下: 5 运行生产文档 每次更新都必须重新编译才能够访问到最新的注释。 6 配置settings.py 在项目根目录下创建static/apidoc 7 配置url 8 浏览器访问 0030 apidoc接口文档 标签:site 插件 app 编译 nucleus word ram pat object 原文地址:https://www.cnblogs.com/dorian/p/12634642.htmlfrom django.shortcuts import render, HttpResponse
from django.views.generic import View
# Create your views here.
class Login(View):
@classmethod
def get(cls, request):
return HttpResponse(‘ok‘)
from django.contrib import admin
from django.urls import path
from nucleus.views import Login
urlpatterns = [
path(‘admin/‘, admin.site.urls),
path(‘Login/‘, Login.as_view()),
]
npm config set registry https://registry.npm.taobao.org
npm config get registry
npm install -g apidoc -g --registry=https://registry.npm.taobao.org
from django.shortcuts import render, HttpResponse
from django.views.generic import View
# Create your views here.
class Login(View):
@classmethod
def get(cls, request):
"""
@api {GET} /Login/登录操作
@apiVersion 0.0.1
@apiName Login
@apiGroup User
@apiDescription 这里可以描述一下这个函数的具体操作
这一行也可以描述的
@apiParam {String} name 姓名
@apiParam {String} password 密码
@apiSuccess {Object} status 状态码
@apiSuccess {Object} msg 简略描述
@apiSuccessExample Response-Success:
HTTP 1.1/ 200K
{
‘status‘: 0,
‘msg‘: ‘success‘
}
@apiErrorExample Response-Fail:
HTTP 1.1/ 404K
{
‘status‘: 1,
‘msg‘: ‘Fail‘
}
"""
return HttpResponse(‘ok‘)
{
"name": "测试",
"version": "0.0.1",
"description": "API文档测试",
"title": "API文档测试",
"url" : "http://xxxxxxx",
"sampleUrl" : "http://xxxxxxxx",
"template":{
"forceLanguage":"zh_cn"
}
}
apidoc -i nucleus/ -o static/apidoc # nucleus是APP目录
STATIC_ROOT = os.path.join(BASE_DIR, ‘static‘)
APIDOC_ROOT = os.path.join(STATIC_ROOT, ‘apidoc‘)
from django.contrib import admin
from django.urls import path, re_path
from nucleus.views import Login
from django.views.static import serve
from django.conf import settings
urlpatterns = [
path(‘admin/‘, admin.site.urls),
path(‘Login/‘, Login.as_view()),
re_path(r‘^apidoc/(?P
http://127.0.0.1:8000/apidoc/index.htm