---
title: "如何利用apidoc自动生成文档"
author: "xiaolin0199"
date: "2018-08-02T13:44:20Z"
tags: []
categories: ["互联网"]
slug: "apidoc"
draft: false
lastmod: "2018-08-02T15:20:39Z"
id: 2427949
url: "https://xiaolin0199.iteye.com/blog/2427949"
---

参考如下:

1\. http://apidocjs.com/

2\. http://www.bjhee.com/apidoc.html

3\. https://cloud.tencent.com/developer/article/1005271

4\. http://hinylover.space/2016/03/31/create-online-document-use-apidoc/

5\. https://fxm5547.com/%E6%8A%80%E6%9C%AF%E8%A7%84%E8%8C%83/2017/11/08/apiDoc-define-standard/

6. https://www.jianshu.com/p/a799c23234b8

7. https://blog.csdn.net/weixin\_40475396/article/details/80352744

 

简单的配置如下：( Django )

1\. 安装apidoc, 

写道

npm install apidoc -g

2\. 按apidoc语法写好文档，参考5是一篇very good的语法规范

3\. 生成apidoc文档，我这里是放在项目根目录下的static文件夹的apidoc目录

    先在项目根目录下放一个apidoc.json文件，示例如下:

```
{
  "name": "测试",
  "version": "0.0.1",
  "description": "API文档测试",
  "title": "API文档测试",
  "url" : "http://xxxxxxx",
  "sampleUrl" : "http://xxxxxxxx",
  "template":{
    "forceLanguage":"zh_cn"
  }
}
```

 

写道

apidoc -i 你的文档代码路径 -o static/apidoc

4\. 修改 settings.py , 添加下面代码

```
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

APIDOC_ROOT = os.path.join(STATIC_ROOT, 'apidoc')
```

5\. 修改 urls.py , 添加下面代码

```
from django.views.static import serve

from django.conf import settings

urlpatterns = [

    url(r'^apidoc/(?P<path>.*)$', serve, {'document_root': settings.APIDOC_ROOT}),

    ....

]
```

6\. 运行runserver , localhost:8000/apidoc/index.html　试试看吧!