# Flask-Docs
[![Build Status](https://travis-ci.org/kwkwc/flask-docs.svg?branch=master)](https://travis-ci.org/kwkwc/flask-docs)
[![Coverage Status](https://coveralls.io/repos/github/kwkwc/flask-docs/badge.svg?branch=master)](https://coveralls.io/github/kwkwc/flask-docs?branch=master)
[![PyPI](https://img.shields.io/pypi/v/Flask-Docs)](https://pypi.org/project/Flask-Docs/)
> Adds Docs support to Flask.
[简体中文](README.zh-CN.md)
Features
-----
- Automatic generation of markdown documentation
- Support for generating offline documentation
- Support Flask-RESTful
- Support flask.views.MethodView
Usage
-----
Here is an example:
```python
from flask import Flask
from flask_docs import ApiDoc
app = Flask(__name__)
# Using CDN
# app.config["API_DOC_CDN"] = True
# Disable document pages
# app.config["API_DOC_ENABLE"] = False
# Methods allowed to be displayed
# app.config["API_DOC_METHODS_LIST"] = ["GET", "POST", "PUT", "DELETE", "PATCH"]
# Custom url_prefix
# app.config["API_DOC_URL_PREFIX"] = "/docs/api"
# Restful API documents to be excluded
# app.config["API_DOC_RESTFUL_EXCLUDE"] = ["todo"]
# Api Document needs to be displayed
app.config["API_DOC_MEMBER"] = ["api", "platform"]
ApiDoc(app)
```
How to add markdown documents to the code:
```
@@@
# Write your markdown document here
@@@
```
# Run in /docs/api/
Api and document pages
-----
````python
@api.route("/add_data", methods=["POST"])
def add_data():
"""Add some data
@@@
### args
| args | nullable | request type | type | remarks |
|-------|----------|--------------|------|----------|
| title | false | body | str | blog title |
| name | false | body | str | person's name |
### request
```json
{"title": "xxx", "name": "xxx"}
```
### return
```json
{"code": xxxx, "msg": "xxx", "data": null}
```
@@@
"""
return jsonify({"api": "add data"})
````
![sample_app](flask_docs/assets/sample_app_add.png)
````python
@api.route("/delete_data", methods=["GET"])
def delete_data():
"""Delete some data
@@@
### args
| args | nullable | request type | type | remarks |
|--------|----------|--------------|------|--------------|
| id | true | query | str | blog id |
| name | false | query | str | person's name |
### request
```
http://127.0.0.1:5000/api/delete_data?name=xxx
```
### return
```json
{"code": xxxx, "msg": "xxx", "data": null}
```
@@@
"""
return jsonify({"api": "delete data"})
````
![sample_app](flask_docs/assets/sample_app_delete.png)
````python
@platform.route("/get_something", methods=["GET"])
def get_something():
"""Get some data
@@@
### request example
```python
import requests
url="http://127.0.0.1:5000/platform/get_something"
try:
print(requests.get(url).text)
except:
pass
```
### return
```json
{"code": xxxx, "msg": "xxx", "data": null}
```
@@@
"""
return jsonify({"platform": "get something"})
````
![sample_app](flask_docs/assets/sample_app_get.png)
Flask-RESTful Api and document pages
-----
````python
from flask_restful import Resource, Api
class Todo(Resource):
"""Manage todo"""
def post(self):
"""Add todo
@@@
### description
> Add todo
### args
| args | nullable | request type | type | remarks |
|-------|----------|--------------|------|----------|
| name | false | body | str | todo name |
| type | false | body | str | todo type |
### request
```json
{"name": "xx", "type": "code"}
```
### return
```json
{"code": xxxx, "msg": "xxx", "data": null}
```
@@@
"""
return {"todo": "post todo"}
def get(self):
"""Get todo
@@@
### description
> Get todo
### args
| args | nullable | request type | type | remarks |
|-------|----------|--------------|------|----------|
| name | false | query | str | todo name |
| type | true | query | str | todo type |
### request
```
http://127.0.0.1:5000/todo?name=xxx&type=code
```
### return
```json
{"code": xxxx, "msg": "xxx", "data": null}
```
@@@
"""
return {"todo": "get todo"}
restful_api.add_resource(Todo, "/todo")
````
![sample_app](flask_docs/assets/sample_app_restful_post.png)
![sample_app](flask_docs/assets/sample_app_restful_get.png)
flask.views.MethodView Api
-----
> ***For the time being, only url_rule with the same class name are supported***
```python
from flask.views import MethodView
class TodoList(MethodView):
"""Manage todolist"""
def put(self):
"""Change the data"""
return jsonify({"todos": "put todolist"})
def delete(self):
"""Delete the data"""
return jsonify({"todos": "delete todolist"})
app.add_url_rule("/todolist/", view_func=TodoList.as_view("todolist"))
```
Decorator @ApiDoc.change_doc
-----
> Reuse comments
```python
from flask_docs import ApiDoc
return_json_str = '{"code": xxxx, "msg": "xxx", "data": null}'
@api.route("/add_data", methods=["POST"])
@ApiDoc.change_doc({"return_json": return_json_str})
def add_data():
"""Add some data
@@@
### return
```json
return_json
```
@@@
"""
return jsonify({"api": "add data"})
@api.route("/delete_data", methods=["GET"])
@ApiDoc.change_doc({"return_json": return_json_str})
def delete_data():
"""Delete some data
return_json
"""
return jsonify({"api": "delete data"})
```
Examples
-----
[Complete example][examples]
Installation
-----
`pip3 install Flask-Docs`
Reference
-----
[flask_api_doc](https://github.com/tobyqin/flask_api_doc/)
[Flask-Bootstrap](https://github.com/mbr/flask-bootstrap/)
[github-markdown-css](https://github.com/sindresorhus/github-markdown-css/)
[examples]: https://github.com/kwkwc/flask-docs/tree/master/examples
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源分类:Python库 所属语言:Python 资源全名:Flask-Docs-0.3.8.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源详情
资源评论
资源推荐
收起资源包目录
Flask-Docs-0.3.8.tar.gz (34个子文件)
Flask-Docs-0.3.8
MANIFEST.in 139B
PKG-INFO 779B
flask_docs
templates
index.html 8KB
css_template_cdn.html 278B
js_template_local.html 328B
css_template_local.html 203B
js_template_cdn.html 484B
assets
sample_app_restful_post.png 31KB
sample_app_get.png 31KB
sample_app_restful_get.png 31KB
sample_app_delete.png 34KB
sample_app_add.png 34KB
static
css
github-markdown-1.0.0.min.css 14KB
fonts
element-icons.ttf 55KB
element-icons.woff 28KB
index-2.14.0.min.css 227KB
github-gist-10.3.2.min.css 713B
js
highlight-10.3.2.min.js 105KB
marked-1.2.2.min.js 35KB
vue-2.6.12.min.js 91KB
index-2.14.0.min.js 551KB
axios-0.21.0.min.js 14KB
FileSaver-2.0.2.min.js 3KB
__init__.py 13KB
LICENSE 1KB
setup.cfg 38B
setup.py 1KB
Flask_Docs.egg-info
PKG-INFO 779B
requires.txt 20B
not-zip-safe 1B
SOURCES.txt 1KB
top_level.txt 11B
dependency_links.txt 1B
README.md 6KB
共 34 条
- 1
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0