0

Is it ways to document my html template right from flask views like that?:

@app.route('/data_transcript', methods=['GET', 'POST'])
def data_transcript():
    """string for html template"""
    # to do some stuff
    return render_template('index.html', doc_string= """string for html template""")

index.html :

<html>
<body>
{{doc_string}}
</body>
</html>
  • Does this answer your question? [Python introspection: access function name and docstring inside function definition](https://stackoverflow.com/questions/10037825/python-introspection-access-function-name-and-docstring-inside-function-definit) – njzk2 Jul 27 '22 at 13:27

1 Answers1

1

You can access the doc string for a function in it's __doc__ attribute, so you can write:

@app.route('/data_transcript', methods=['GET', 'POST'])
def data_transcript():
    """string for html template"""
    # to do some stuff
    return render_template('index.html', doc_string=data_transcript.__doc__)
larsks
  • 277,717
  • 41
  • 399
  • 399