You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -13,7 +12,7 @@ function arguments and docstring.
13
12
14
13
## Requirements
15
14
16
-
FlaskAutodoc is compatible with Python versions 2 and 3; and depends only on Flask.
15
+
Flask-Autodoc is compatible with Python versions 2 and 3; and it depends only on Flask.
17
16
18
17
## Install
19
18
@@ -35,28 +34,28 @@ Start using Flask-Autodoc by importing it and initializing it:
35
34
app = Flask(__name__)
36
35
auto = Autodoc(app)
37
36
38
-
by default, Flask-Autodoc will only document the routes you explicitly tell him to with the _doc_ decorator,
39
-
like this:
37
+
by default, Flask-Autodoc will only document the routes explicitly decorated with _doc_:
40
38
41
39
@app.route('/user/<int:id>')
42
40
@auto.doc()
43
41
def show_user(id):
44
-
"""This returns a user with a given id."""
45
42
return user_from_database(id)
46
43
47
-
to generate the documentation from an endpoint, use the _html()_ method:
44
+
to generate the documentation, use the _html()_ method:
48
45
49
46
@app.route('/documentation')
50
47
def documentation():
51
48
return auto.html()
52
49
53
-
if you to access the documentation without it being rendered in html:
50
+
## Custom documentation
51
+
52
+
To access the documentation without rendering html:
54
53
55
54
@app.route('/documentation')
56
55
def documentation():
57
56
return auto.generate()
58
57
59
-
the documentation will then be returned as a list of rules, where each rule is a dictionary containing:
58
+
the documentation will be returned as a list of rules, where each rule is a dictionary containing:
60
59
61
60
- methods: the set of allowed methods (ie ['GET', 'POST'])
62
61
- rule: relative url (ie '/user/<int:id>')
@@ -65,34 +64,55 @@ the documentation will then be returned as a list of rules, where each rule is a
65
64
- args: function arguments
66
65
- defaults: defaults values for the arguments
67
66
68
-
## Groups
67
+
## Custom template
68
+
69
+
To use a custom template for your documentation, give a _template_ argument to the _html_ method. This will use a template from the flask _templates_ directory.
70
+
71
+
Additionnal arguments (other than _group_, _groups_, and _template_) will be passed down to the template:
72
+
73
+
auto.html(
74
+
75
+
template='custom_documentation.html'
76
+
77
+
title='My Documentation',
78
+
author='John Doe',
79
+
)
80
+
81
+
82
+
_title_ and _author_ will be available in the template:
69
83
70
-
You may want to group endpoints together, to have different documentation sets. With this you can for example, only
71
-
show some endpoints to third party developer and have full documentation for your own.
84
+
<!-- templates/custom_documentation.html -->
85
+
...
86
+
{% if title is defined %}
87
+
{{title}}
88
+
{% endif %}
89
+
...
72
90
73
-
to assign an endpoint to a group, pass the name of the group as argument of the _doc_ decorator:
91
+
## Documentation sets
92
+
93
+
Endpoints can be grouped together in different documentation sets. It is possible for instance to show some endpoints to third party developers and have full documentation for primary developers.
94
+
95
+
To assign an endpoint to a group, pass the name of the group as argument of the _doc_ decorator:
74
96
75
97
@app.route('/user/<int:id>')
76
-
@auto.doc("public")
98
+
@auto.doc('public')
77
99
def show_user(id):
78
100
79
101
to assign an endpoint to multiple groups, pass a list of group names as the _groups_ argument to _doc_:
80
102
81
103
@app.route('/user/<int:id>')
82
-
@auto.doc(groups=["public","private"])
104
+
@auto.doc(groups=['public','private'])
83
105
def show_user(id):
84
106
85
-
to generate the documentation for a specific group, pass the name of the group to the _generate_ or _html_ methods:
86
-
87
-
auto.generate("public")
88
-
89
-
or
90
-
91
-
auto.html("public")
107
+
to generate the documentation for a specific group, pass the name of the group to the _html_ or _generate_ methods:
92
108
109
+
auto.html('public')
110
+
auto.html(groups=['public','private'])
111
+
auto.generate('public')
112
+
93
113
## Examples
94
114
95
-
Apps in the _examples_ directory mock a blog.
115
+
Apps in the _examples_ directory are an api for a blog:
0 commit comments