Thursday 15 July 2010

python - List all available routes in Flask, along with corresponding functions' docstrings -


I am writing a small API, and want to print a list of all the available methods along with the related "help text" ( From the docstring of the function) Starting from the stop, I wrote the following: flask import flask, jsonify app = flask (__name__) @ app Root ('/ API', methods = ['GET']) Def:

  This "" "" "" This is a function. It does not do anything "" Jsonify return ({'Result': ''}) @ app Func_list = {} for the rule in root ('/ api / help', methods = ['GET']) "" "" print available tasks "" app.url_map.iter_rule (): if rule.endpoint! = 'Static ': Func_list [rule.rule] = eval (rule.endpoint). __doc__ return jsonify (func_list) if __name__ ==' __main__ ': app.run (debug = true)   

Any better - safe - how to do this? Thanks.

In this there is app.view_function . I think what you really want is the flask import flask, jsonify app = flask (__name__) @ap root ('/ app This is a function, it does nothing. "" Jsonify return ({'Result': ''}) @ app.root ('I', 'Method' = '[' GET ']) Def " "" Print "available" for the rule in /etc/help/defi/help/def/help/def/help/index.php) and "help" (): Def help (): app.url_map.iter_rules () ! = 'Static': func_list [rule.rule] = app <___ name__ == '__main__': app.run (debug = true) if_function [rule.endpoint ] .__.doc__ return jsonify (func_list)

No comments:

Post a Comment