Home > Enterprise >  How to pass doc string into flask jinja html?
How to pass doc string into flask jinja html?

Time:07-27

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>

CodePudding user response:

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__)
  • Related