# Flask-Docs
[](https://travis-ci.org/kwkwc/flask-docs)
[](https://coveralls.io/github/kwkwc/flask-docs?branch=master)
[](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"})
````

````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"})
````

````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"})
````

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")
````


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

挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
最新资源
- 《ACM-ICPC 的参考资料》(毕业设计,源码,教程)简单部署即可运行 功能完善、操作简单,适合毕设或课程设计.zip
- CO2驱替甲烷的深度探讨与研究基于Comsol数值模拟分析,基于COMSOL软件的二氧化碳驱替甲烷技术研究,comsol 二氧化碳驱替甲烷 ,COMSOL模拟; 二氧化碳驱替; 甲烷浓度变化; 数值模
- 基于stm32和proteus的家居环境采集仿真设计,采集家居环境的信温湿度、光照值以及气体检测(源码+报告+演示视频)
- 《2021 数模美赛O奖论文及代码公开》(毕业设计,源码,教程)简单部署即可运行 功能完善、操作简单,适合毕设或课程设计.zip
- dvanced archive password recovery pro v4.54
- 《2024蓝桥杯嵌入式学习资料》(毕业设计,源码,教程)简单部署即可运行 功能完善、操作简单,适合毕设或课程设计.zip
- JavaEE框架及关键技术的设计与实现指南:面向企业级应用
- MATLAB Simulink仿真研究:永磁同步电机FOC矢量控制与DTC矢量控制的动静态性能对比分析,MATLAB Simulink仿真研究:永磁同步电机FOC矢量控制与DTC矢量控制的动静态性能对
- 液压.zip
- 一体空间站 1.zip
- STM32学习标准库实现STM32 ADC采集1路、2路、多路
- STEP7-MicroWIN-SMART-V2.8库包括模拟量比例换算指令库
- 银河系加昼夜地球.zip
- 银河系扩展包2.81.3—1.5移植版(1.4移植1.5).zip
- 银河系扩展包2.6by航天星辰.zip
- 宇航员.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



评论0